首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >嵌套指令在加载时不触发

嵌套指令在加载时不触发
EN

Stack Overflow用户
提问于 2015-12-29 05:34:35
回答 2查看 58关注 0票数 0

我是AngularJS的新手,在使用嵌套指令时遇到了问题。我有两个指令:

MainDir.js

代码语言:javascript
复制
(function(){angular.module("mod").directive("mainDir", function(){
return {
    restrict: "E",
    scope: {},
    link: function(scope, element, attributes) {   
    },
    templateUrl: "components/main.html"
};
});})();

Main.html

代码语言:javascript
复制
<div>Main html</div>
<childDir> </childDir>

childDir.js

代码语言:javascript
复制
(function(){angular.module("mod").directive("childDir", function(){
return {
    restrict: "E",
    scope: {},
    link: function(scope, element, attributes) {   
    },
    templateUrl: "components/child.html"
};
});})();

child.html

代码语言:javascript
复制
<p>Hello World</p>

在页面加载时,我在main.html中获得div中的文本,但指令没有加载。我在link函数中设置了一些断点,但它没有到达那里。

EN

回答 2

Stack Overflow用户

发布于 2015-12-29 05:48:27

你打错了。

childDir.js中,将templateUrl更改为template

票数 1
EN

Stack Overflow用户

发布于 2015-12-29 06:41:56

问题是,子指令的标记需要写成

代码语言:javascript
复制
<child-dir></child-dir>

在这之后它起作用了..

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34501083

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档