- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2022 08:10 AM
Hello,
I have a service portal widget that displays a table of records. I am trying to print out the row count at the top of my page, but I am unsure of how to pass html value to the client controller. how can I do that?
This is what I have to display the record count:
<tr ng-repeat="comp in results = ( c.data.list | orderBy:sortType:sortReverse | filter:comp_search:strict)">
<span id="record-count" style="float:right;">Records Found: {{results.length}}</span>
I need to get the value from results.length and pass it to the client controller. Then I need to be able to call it back in the HTML.
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2022 09:22 AM
Ah, it is because of your ng-if here:
<div ng-if="c.data.list" class="panel-body vdp table-responsive">
Instead of ng-if, try using ng-show instead:
<div ng-show="c.data.list.length > 0" class="panel-body vdp table-responsive">
Please mark helpful or mark as correct answer if applicable 🙂
Best regards,
Sebastian Laursen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2022 11:13 AM
You can access data object(generated in server script) directly in your client script. If you have create any input element then you can access as below,
<input ng-model="c.fname" type="text" />
<button ng-click="c.showAlert()">Click</button>
In client script,
c.showAlert = function(){
alert(c.fname);
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2022 12:10 PM
Hm, I think this is a little bit tricky, since it is a value you get from a filtered list. Normally you will bind data from html to client with a ng-model.
Why is it you need it in the Client Controller and when do you need? Is it after a click of a button or something else? If the latter, then maybe something like this - again, depending on your actual use case - just an example on how to pass data from html to client:
//HTML
<input type="text" ng-model="fname" name="fname" ng-init="fname=results.length" ng-hide="true">
<button ng-click="doStuffToThis()">Click me</button>
//Client controller
$scope.doStuffToThis = function(){
console.log('hello2 '+$scope.fname);
}
Best regards,
Sebastian Laursen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2022 12:28 PM
***EDIT***
The way I currently have it without the client controller works just fine to display the total output, but I wanted to move it outside of the table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2022 12:50 PM
Ah, should be more simple then, so use the same approach with ng-model and ng-init to store the value. Then outside of the div refer to the ng-model as below {{fname}}
<div>
<tr ng-repeat="comp in results">
<span>Records Found: {{results.length}}</span>
<input type="text" ng-model="fname" name="fname" ng-init="fname=results.length" ng-hide="true">
</tr>
</div>
<!-- Here outside of div you can call the ng-model and display the data by refering to the above ng-model -->
<div type="text">{{fname}}</div>
Best regards,
Sebastian Laursen