How do I pass multiple attributes into an Angular.js attribute directive?

后端 未结 5 1006
长发绾君心
长发绾君心 2020-11-30 18:57

I have an attribute directive restricted as follows:

 restrict: \"A\"

I need to pass in two attributes; a number and a function/callback, a

5条回答
  •  执念已碎
    2020-11-30 19:23

    If you "require" 'exampleDirective' from another directive + your logic is in 'exampleDirective's' controller (let's say 'exampleCtrl'):

    app.directive('exampleDirective', function () {
        return {
            restrict: 'A',
            scope: false,
            bindToController: {
                myCallback: '&exampleFunction'
            },
            controller: 'exampleCtrl',
            controllerAs: 'vm'
        };
    });
    app.controller('exampleCtrl', function () {
        var vm = this;
        vm.myCallback();
    });
    

提交回复
热议问题