I'm trying to create a reusable list-like directive. Example code is without styling, etc.
The code does invoke the callback but no argument is passed. Ideally, it would return the object for that row or its index.
Any help would be greatly appreciated.
Directive:
module.directive('quicklist', function() {
return {
restrict:'E',
scope: {
data: '=ngModel',
clickFn: '&callback'
}
template:'<ul><li ng-repeat="d in data"><a href="" ng-click="clickFn(d)">{{d}}</a></li></ul>'
};
});
HTML:
<quicklist ng-model='array' callback='work(arg)'><quicklist>
When I pass functions to be used with parameters in the directive, i use the =
binding:
scope: {
data: '=ngModel',
clickFn: '=callback'
}
And in your HTML just pass the function's name without the argument:
<quicklist ng-model='array' callback='work'><quicklist>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.