我有多个指令实例,我只想针对特定实例。例如在下面的代码中,如何确保 divclass="one"
是唯一由 event 触发的$rootScope.$broadcast('myEvent')
。
JS:
myApp.directive('myDirective', function() {
return {
restrict: 'A',
controller: function(scope, el, attrs) {
scope.$on('myEvent', function() {
el.css({left: '+=100'});
});
},
};
});
HTML:
<div my-directive class="one"></div>
<div my-directive class="two"></div>