【发布时间】:2018-05-01 17:35:34
【问题描述】:
我写了一个表格组件:
<table ng-model="$ctrl.model" class="table" md-progress="promise">
<thead class="thead">
<tr>
<th class="theader">ID</th>
<th class="theader">A</th>
<th class="theader">Actions</th>
</tr>
</thead>
<tbody>
<tr md-row ng-repeat="row in $ctrl.data track by $index">
<td width="15%" class="trow">{{row.id}}</td>
<td width="15%" class="trow">{{row.a}}</td>
<td width="15%" class="trow">
<md-button ng-click="$ctrl.edit({x: row.id, y: row.a})"></md-button>
</td>
</tr>
</tbody>
我将组件定义为:
.component('tablesample', {
require: {},
templateUrl: 'Components/templates/tableSample.html',
bindings: {
data: '=',
model: '=',
edit: '&',
},
controller: function ($log) {
var tbl = this;
tbl.$onInit = function () {
};
tbl.$onChanges = function () {
};
}
})
我称新组件为:
<tablesample data="tableData" model="selectedRow" edit="editFunction()"></tablesample>
编辑函数定义为:
$scope.editFunction = function(x,y){
console.clear();
$log.info(x);
$log.info(y);
};
日志语句总是显示“未定义”,我不知道为什么,填充了 row.id,如果我转储它,我可以看到 1、2、3 等.... 在 editFunction 中我做了一个 http get因此,如果 x 未定义,则调用将失败。
谁能看出我做错了什么?
谢谢 D
【问题讨论】:
标签: javascript angularjs components