无法编译带有 ng-transclude 的 AngularJs 指令模板 [英] AngularJs Directive Template with ng-transclude cannot be compiled

查看:26
本文介绍了无法编译带有 ng-transclude 的 AngularJs 指令模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建两个指令.第一个指令将其他预定义的角度指令(ng-click 和 ng-class)附加到元素,然后编译它以便它们工作.

I am trying to create two directives. The first directive appends other predefined angular directives (ng-click and ng-class) to the element and then compiles it so that they work.

第二个指令替换包含第一个指令的模板的元素.我使用 ng-transclude 将元素的内容传送到模板.

The second directive replaces an element for a template which contains the first directive. I use ng-transclude to carry the element's contents over to the template.

问题是,一旦添加了指令 2 的模板,第一个指令就会尝试编译并抛出一个 wobbly:

The problem is that once the template from directive 2 is added the first directive tries to compile and throws a wobbly:

类型错误:未定义不是函数"

"TypeError: undefined is not a function"

当模板中不存在 ng-transclude 时,指令 1 工作正常.我创建了一个 Plunk 来证明这一点:http://plnkr.co/edit/RdtjIy5XKOsqvh5VnwMr

Directive 1 works fine when ng-transclude is not present in the template. I have created a Plunk to demonstrate this: http://plnkr.co/edit/RdtjIy5XKOsqvh5VnwMr

有人能帮忙指出我哪里出错了吗?

Is anyone able to help out and point out where I am going wrong?

谢谢,山姆

推荐答案

经过进一步的反复试验,我找到了解决方法,据我所知,没有任何副作用.

After further trial and error I have found a fix and as far as I can tell, there are no side-effects.

我只是从第二个指令中删除了 ng-transclude 属性.我在这里有一个更新的 Plunk:http://plnkr.co/edit/9QXkqzzyUy9VvMYC6fO6

I simply remove the ng-transclude attribute from within the second directive. I have an updated Plunk here: http://plnkr.co/edit/9QXkqzzyUy9VvMYC6fO6

这篇关于无法编译带有 ng-transclude 的 AngularJs 指令模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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