(using angular 1.5)
I have a parent component (main) passing an bunch of data to a child component (child1).
This child component (child1) displays the data in a table. The rows of the table have an ng-click that stores a value when clicked (an integer).
here is the html of the main component:
<child2 sent-id = "$ctrl.sendCopy"></child2>
<child1 data = "$ctrl.stuff"></child1>
You can see child1 stores the stuff array as data (which is bound in the child 1 component)
I store the table value that is clicked like this:
function Child1Controller(){
this.storeId = function(id){
this.sendCopy = id;
}
}
then in child2 I bind sentId like so
bindings: {
sentId: '='
},
And just try to display it in the html but it isnt getting passed.
I feel like his is something really simple. Thanks
EDIT (more code): Child 1 component
angular.module('main').component('child1', {
templateUrl: 'scripts/components/child1.html',
bindings: {
data: '<',
},
controller: Child1Controller
});
function Child1Controller($log){
this.storeId = function(id){
this.sendCopy = id;
}
}
Child1 html:
<div class="panel panel-default">
<div class="panel-body">
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Id</th>
</tr>
</thead>
<tbody>
<tr ng-click="$ctrl.storeId(data.id)" ng-repeat="data in $ctrl.data | filter:data.name">
<td>{{data.name}}</td>
<td>{{data.id}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
Child2 component
angular.module('main').component('child2', {
templateUrl: 'scripts/components/child2.html',
bindings: {
sentId: '='
},
controller: Child2Controller
});
function Child2Controller() {
}
Child2 html
<div class="panel panel-default">
<div class="panel-body">
<div>
</div>
<div>
ID = {{ $ctrl.sentId }}
</div>
</div>
</div>