【发布时间】:2016-11-30 02:18:57
【问题描述】:
(使用角度 1.5)
我有一个父组件(main)将一堆数据传递给一个子组件(child1)。
此子组件 (child1) 在表格中显示数据。表格的行有一个 ng-click,点击时会存储一个值(一个整数)。
这里是主要组件的html:
<child2 sent-id = "$ctrl.sendCopy"></child2>
<child1 data = "$ctrl.stuff"></child1>
可以看到 child1 将 stuff 数组存储为数据(绑定在 child 1 组件中)
我这样存储被点击的表值:
function Child1Controller(){
this.storeId = function(id){
this.sendCopy = id;
}
}
然后在 child2 中我像这样绑定 sendId
bindings: {
sentId: '='
},
只是尝试在 html 中显示它,但它没有通过。
我觉得他的东西很简单。 谢谢
编辑(更多代码): 子 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>
【问题讨论】:
-
您能提供更多上下文吗?
-
你可以为你的问题发布更多代码
-
我根据您的附加代码更新了下面的答案。
标签: angularjs angular-components