angularjs - Using ng-click in directive's template to call other directive -
i want use ng-click
inside directive's template, don't know how can pass directive it. code follows:
template: ` <ul><li ng-repeat="link in $ctrl.map" ng-click="page-scroll-to={{link[1]}}">{{link[0]}}</li></ul> `
secound directive:
app.directive('pagescrollto', () => { return { link(scope, el, attrs) { const scroll = attrs.pagescrollto; window.scrollto(0, scroll); } }; });
it, obviously, doesn't work. how can make work?
in directive, put click handler on element.
template:
<ul> <li ng-repeat="link in $ctrl.map" page-scroll-to="link[1]"> {{link[0]}} </li> </ul>
the directive:
app.directive('pagescrollto', () => { return { link: function (scope, elem, attrs) { elem.on("click", function clickhandler(e) { var scroll = scope.$eval(attrs.pagescrollto); window.scrollto(0, scroll); }); } }; });
Comments
Post a Comment