In the code below, how does the angular directive 'myscroll' know what ng-repeat elements are being created?
<myscroll>
<div ng-repeat="a in arr">{{a}}</div>
</myscroll>
I know that the $last event is not fired to the parent directive, how can I solve this?
myapp.directive("myscroll", function () {
return{
restrict: "E",
transclude: true,
template: "<span class='left'></span><div class='mask' ng-transclude></div><span class='right'></span>",
link: function (scope, element, attr) {
scope.$watch("$last",function(){ console.log("ng-repeat rendered") })
}
}
})
A simple way to do it is to create a new directive called 'repeat-done' and use it where the 'ng-repeat' is. Then you can notify the 'myscroll' directive (parent scope) whatever you need.
<myscroll>
<div ng-repeat="a in arr" repeat-done>{{a}}</div>
</myscroll>
myapp.directive('repeatDone', [function () {
return {
restrict: 'A',
link: function (scope, element, iAttrs) {
var parentScope = element.parent().scope();
if (scope.$last){
// ng-repeat is completed and you now have access to 'myscroll' scope
console.log(parentScope);
}
}
};
}])
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