I want to call a scope function inside my ng-repeat
just for the last element, like this:
<div ng-repeat="patient in patients" >
<div ng-if="$last" ng-load="myFunction()"></div>
</div>
But ng-load
doesn't work!
You can use $last variable within ng-repeat directive. Take a look at doc. Where computeCssClass is function of controller which takes sole argument and returns 'last' or null .
Directives that Create Scopes In most cases, directives and scopes interact but do not create new instances of scope. However, some directives, such as ng-controller and ng-repeat, create new child scopes and attach the child scope to the corresponding DOM element.
Note: The $index variable is used to get the Index of the Row created by ng-repeat directive. Each row of the HTML Table consists of a Button which has been assigned ng-click directive. The $index variable is passed as parameter to the GetRowIndex function.
The data-ng-repeat allows the HTML to be validated through validators that do not understand Angular. The documentation is here with directives. This is from the docs: Angular normalizes an element's tag and attribute name to determine which elements match which directives.
I think this should work:
<div ng-repeat="element in array" ng-init="$last && myFunction(element)">
{{element}}
</div>
There you have working JSFiddle.
Use ng-init="$last && myFunction()", that should do the same thing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With