角指令不工作 [英] Angular directive is not working

查看:141
本文介绍了角指令不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请找我写的指令,

angular.module('netVogue.directives', []).
  directive('set-First-Active', function() {
      return function(scope, element, attrs){
          alert('sample');
          element.addClass("active");     
      };
  });

我在下面的方式加入这个指令到我的模块,

I have added this directive to my module in below way,

angular.module('netVogue', ['netVogue.filters', 'netVogue.services', 'netVogue.directives']);

我用这个指令在我的模板格式如下,

I used this directive in my template in following format,

<div class="item" ng-repeat="viewPrintcampaign in viewPrintcampaigns" ng-init="first=$first" set-First-Active> 
</div>

不过,我既看不到戒备任何回应也不是获取添加类。
是否有人可以帮助我?
由于一些依赖,我不想用'纳克级',但要添加class ='​​积极'的NG-重复的第一个元素。
任何帮助将大大AP preciated。先谢谢了。

However, i neither see any response of alert nor class is getting added. Can someone please help me with this? Due to some dependency, i don't want to use 'ng-class' but want to add class='active' for the first element of ng-repeat. Any help would be greatly appreciated. Thanks in advance.

阿卜杜勒

推荐答案

在申报指令应具备驼峰名( setFirstActive )。

When declaring directive should has camel case name (setFirstActive).

请参阅开发人员指南,指示的。

指令有骆驼套管的名称,如ngBind。该指令可以通过这些特殊字符转换骆驼案件名称为蛇的情况下被调用:, - 或_。可选的指令可以prefixed以x-或DATA-使它HTML验证标准。下面是一些可能的指令名称的列表:NG:绑定,NG绑定,ng_bind,X-NG-绑定和数据NG绑定

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.

这篇关于角指令不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆