如何在 AngularJS 中将数据从父级发送到子级
How to send data from the Parent to the Child in the AngularJS
如何将数据从 Parent Controller(索引)发送到 Child Controller(组件)。请查看示例,而不是硬编码 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;
}
在你的 plunker 中,这样做:
<test-component value="vm.obj"> </test-component>
您将 obj
的值放入变量 value
中。因此,在子作用域中,您可以使用 var value
访问此值,而不再使用 obj
.
Here 你的 plunker 更新了吗。
如何将数据从 Parent Controller(索引)发送到 Child Controller(组件)。请查看示例,而不是硬编码 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;
}
在你的 plunker 中,这样做:
<test-component value="vm.obj"> </test-component>
您将 obj
的值放入变量 value
中。因此,在子作用域中,您可以使用 var value
访问此值,而不再使用 obj
.
Here 你的 plunker 更新了吗。