[英]Angular 1.5 nesting components
I have a container component that has 2 other controllers nested in it. 我有一个容器组件,其中嵌套有2个其他控制器。 I have them set up like so
container -> component1
and container -> component2
我像这样设置它们
container -> component1
和container -> component2
My train of thought here was that I could transclude the HTML from my page into my container component. 我在这里的思路是,我可以将HTML从页面中移到容器组件中。
<container> <component1></component1> <component2></component2></container>
and then in the container HTML <div ng-init="vm.init()" ng-transclude></div>
然后在容器HTML
<div ng-init="vm.init()" ng-transclude></div>
Problem is, my container isn't running at all, I added a console log to its init function and no code is running. 问题是,我的容器根本没有运行,我向其init函数添加了控制台日志,并且没有代码在运行。 While component1 and component2 run their init's.
当component1和component2运行其init时。
Seems to be a large amount of documentation covering older angular versions. 似乎是大量的文档,涵盖了较旧的角度版本。 Which tell me that they need to be nested like so
<div ng-controller="parentController"> <div ng-controller="childController"></div> </div
哪个告诉我它们需要像这样嵌套
<div ng-controller="parentController"> <div ng-controller="childController"></div> </div
How do you nest components into each other in 1.5? 如何在1.5中将组件相互嵌套?
Looks like the issue was that I was attempting to put a ng-init and ng-transclude in the same element. 看起来问题出在我试图将ng-init和ng-transclude放在同一元素中。 My guess is that ng-transclude overrides everything in the element it is on.
我的猜测是ng-transclude会覆盖其所在元素中的所有内容。
so I moved the ng-init to another element and its working fine 所以我将ng-init移到了另一个元素上,并且工作正常
<div ng-transclude ng-init="vm.init()"></div>
changed to 变成
<div ng-init="vm.init()"> <section ng-transclude ></section> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.