Javascript 模板中的角度指令
我正在尝试在我的应用程序中动态加载指令。我创建了一个如下所示的模板:Javascript 模板中的角度指令,javascript,html,angularjs,templates,angularjs-directive,Javascript,Html,Angularjs,Templates,Angularjs Directive,我正在尝试在我的应用程序中动态加载指令。我创建了一个如下所示的模板: <script type="text/ng-template" id="custom-dir"> <custom-dir component="dir"></custom-dir> </script> 以下是模板路径\u到\u dir/custom-dir.html: 以下是指令: app.directive("rootRouting", [function() {
<script type="text/ng-template" id="custom-dir">
<custom-dir component="dir"></custom-dir>
</script>
以下是模板路径\u到\u dir/custom-dir.html:
以下是指令:
app.directive("rootRouting", [function() {
return {
restrict: "E",
scope: {
component: "=component"
},
replace: true,
template: "<div></div>",
link: function($scope, element, $attrs) {
debugger;
});
}
}
}]);
当我运行应用程序时,我可以在dom中看到模板,其中包含指令。问题是link下的组件逻辑永远不会运行。如果我把没有模板的指令放在主js中,一切都会按预期工作
我的场景有什么问题吗?请检查此选项
您正在模板中创建模板。将custom-dir.html更改为以下内容
<root-routing component="component"></root-routing>
<script type="text/ng-template" id="root-routing">
<root-routing component="component"></root-routing>
</script>
app.directive("rootRouting", [function() {
return {
restrict: "E",
scope: {
component: "=component"
},
replace: true,
template: "<div></div>",
link: function($scope, element, $attrs) {
debugger;
});
}
}
}]);
<root-routing component="component"></root-routing>