(使用角1.5)傳遞從一個子組件值到另一個
我有一個父組件(主)傳遞數據的一堆到一個子組件(child1)。
此子組件(child1)將數據顯示在表中。表格的行有一個ng-click單擊時會存儲一個值(一個整數)。
這裏是主要成分的HTML:
<child2 sent-id = "$ctrl.sendCopy"></child2>
<child1 data = "$ctrl.stuff"></child1>
你可以看到child1存儲的東西陣列作爲數據(這是在孩子1組分結合)
我存儲表值點擊這樣的:
function Child1Controller(){
this.storeId = function(id){
this.sendCopy = id;
}
}
然後在我的child2綁定sentId像這樣
bindings: {
sentId: '='
},
只是試圖顯示它在HTML中,但它沒有得到通過。
我覺得他很簡單。 由於
EDIT(多個碼): 兒童1個部件
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部件
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>
你能提供更多的背景? – jkris
你能發佈更多適合您的問題的號碼嗎 – Ajaykumar
增加更多代碼! – Alex