I have two components both linked to the same module:
angular.module('app', []);
The first Component is a simple input field and button
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
};
}
});
The second component is just a repeating P tag based on an array in the controller
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
*/
}
});
How do I get the $ctrl.post() method of the <my-input/> component to send data to the other <my-output/> component so that it can push() it into it's data array and be picked up by the data-ng-repeat?
Alernatively, is it possible to push() directly into the other component's controller.data array?
I mean, they are both just normal old Objects when it comes down to it!