[英]How to send data from the Parent to the Child in the AngularJS
How can I send the data from the Parent Controller (index) to the Child Controller (Component). 如何将数据从父控制器 (索引)发送到子控制器 (组件)。 Please see the example, instead of the hardcoding the
url
I want to send the parameters for the Title
and the URL
from the page controller to the component. 请参见示例,而不是对
url
进行硬编码,我想将Title
和URL
的参数从页面控制器发送到组件。 I'm stuck to send it and I don't know where is the problem. 我一直无法发送,不知道问题出在哪里。
index.html 的index.html
<div>
<my-list obj="vm.obj"></my-list>
</div>
index.controller.js index.controller.js
this.obj = {
testURL: "AngularJS",
testName: "Testing Environment
}
mylistComponent.html mylistComponent.html
<span>{{vm.myTestName}}</span>
<a href="https://en.wikipedia.org/wiki/{{vm.myTestURL}}">AngularJS Wikipedia</a>
mylist.Component.js mylist.Component.js
binding: {
obj: "="
}
this.goToPage = function() {
this.myTestName = this.obj.testName;
this.myTestURL = this.obj.testURL;
}
In your plunker, by doing this : 通过这样做,您可以:
<test-component value="vm.obj"> </test-component>
You put the value of obj
in the var value
. 您将
obj
的值放在var value
。 So in the child scope you can access to this value with the var value
not anymore with obj
. 因此,在子作用域中,可以使用
obj
不再使用var value
来访问此值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.