【发布时间】:2017-06-11 21:30:06
【问题描述】:
我有两个组件都链接到同一个模块:
angular.module('app', []);
第一个组件是一个简单的输入框和按钮
angular.module('app').component('myInput', {
template: '<input data-ng-model="$ctrl.value"/>' +
'<button data-ng-click="$ctrl.post()">Post</button>',
controller: function MyInputController(){
this.value = "";
this.post = function(){
// get this.value from input and send to other component
};
}
});
第二个组件只是一个基于控制器中数组的重复P标签
angular.module('app').component('myOutput', {
template: '<p data-ng-repeat="item in $ctrl.data">{{ item.value }}</p>',
controller: function MyOutputController(){
this.data = [{value: "Example Data"}];
/*
When this receives the data from the other component
it will push() it into this.data
*/
}
});
如何让<my-input/> 组件的$ctrl.post() 方法将数据发送到另一个<my-output/> 组件,以便它可以push() 将它放入它的data 数组并被@987654329 拾取@?
或者,是否可以将push() 直接放入其他组件的controller.data 数组中?
我的意思是,归根结底,它们都是普通的旧对象!
【问题讨论】:
标签: angularjs components