AngularJS指令链接功能无法正常工作 [英] AngularJS directive link function not working

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

问题描述

http://jsfiddle.net/kz26/kH9wg/

我与指令玩弄于AngularJS并试图同时速记指令风格(只返回链接功能)和手写样式(返回指令定义对象的全部或部分。

I'm playing around with directives in AngularJS and have trying both the shorthand directive style (returning only the link function) and the longhand style (returning all or part of a directive definition object.

不幸的是,我只能够得到的指令工作使用 popup2 定义的简写方式(激活一个jQuery弹出)。该手写 popup2 指令似乎并没有在所有的工作,特别是链接函数在我的定义对象是从来没有所谓。什么我需要做的,使这个明确的联系申报工作?

Unfortunately, I've only been able to get the directive working (which activates a jQuery popup) using the shorthand way defined in popup2. The longhand popup2 directive doesn't seem to work at all, and in particular the link function in my definition object is never called. What do I need to do to make this explicit link declaration to work?

推荐答案

您的两个指令有小调整创建指令时,而不是覆盖第一个重复使用相同的模块工作。请参见这个小提琴

Both of your directives work with a small tweak to reuse the same module when creating the directives instead of overwriting the first one. See this fiddle.

而不是做的:

angular.module("app", []).directive('popover1'...

angular.module("app", []).directive('popover2'...

做这样的事情:

var module = angular.module("app", []);

module.directive('popover1'...

module.directive('popover2'...

编辑:文档我看你可以做同样的事情后,原来的职务,以及这样的:

after looking at the docs I see you can do something similar to the original post as well like this:

angular.module('app', []).directive('popover1'...

angular.module('app').directive('popover2'...

在省略后的第一后续调用的第二个参数 [] angular.module 来配置现有模块。

这篇关于AngularJS指令链接功能无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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