加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS指令不起作用

发布时间:2020-12-17 07:25:49 所属栏目:安全 来源:网络整理
导读:请在下面找到我写的指令, angular.module('netVogue.directives',[]). directive('set-First-Active',function() { return function(scope,element,attrs){ alert('sample'); element.addClass("active"); }; }); 我已经通过以下方式将此指令添加到我的模块
请在下面找到我写的指令,
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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读