请在下面找到我写的指令,
angular.module('netVogue.directives',[]). directive('set-First-Active',function() { return function(scope,element,attrs){ alert('sample'); element.addClass("active"); }; });
我已经通过以下方式将此指令添加到我的模块中,
angular.module('netVogue',['netVogue.filters','netVogue.services','netVogue.directives']);
我在以下格式的模板中使用了这个指令,
<div class="item" ng-repeat="viewPrintcampaign in viewPrintcampaigns" ng-init="first=$first" set-First-Active> </div>
但是,我既没有看到任何警报响应,也没有看到类增加.
有人可以帮我这个吗?
由于某些依赖性,我不想使用’ng-class’,但想为ng-repeat的第一个元素添加class =’active’.
任何帮助将不胜感激.提前致谢.
声明指令时应该具有驼峰大小写的名称(setFirstActive).
见developer guide on directives.
Directives have camel cased names such as ‘ngBind’. The directive can be invoked by translating the camel case name into snake case with these special characters :,-,or _. Optionally the directive can be prefixed with x-,or data- to make it HTML validator compliant. Here is a list of some of the possible directive names: ng:bind,ng-bind,ng_bind,x-ng-bind and data-ng-bind.