![](/img/trans.png)
[英]How to send data from child controller to Parent controller in AngularJS?
[英]How to send data from the Parent to the Child in the AngularJS
如何将数据从父控制器 (索引)发送到子控制器 (组件)。 请参见示例,而不是对url
进行硬编码,我想将Title
和URL
的参数从页面控制器发送到组件。 我一直无法发送,不知道问题出在哪里。
的index.html
<div>
<my-list obj="vm.obj"></my-list>
</div>
index.controller.js
this.obj = {
testURL: "AngularJS",
testName: "Testing Environment
}
mylistComponent.html
<span>{{vm.myTestName}}</span>
<a href="https://en.wikipedia.org/wiki/{{vm.myTestURL}}">AngularJS Wikipedia</a>
mylist.Component.js
binding: {
obj: "="
}
this.goToPage = function() {
this.myTestName = this.obj.testName;
this.myTestURL = this.obj.testURL;
}
通过这样做,您可以:
<test-component value="vm.obj"> </test-component>
您将obj
的值放在var value
。 因此,在子作用域中,可以使用obj
不再使用var value
来访问此值。
这是您的朋克更新。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.