gpt4 book ai didi

javascript - AngularJS 组件 - 函数绑定(bind)

转载 作者:太空宇宙 更新时间:2023-11-04 15:26:32 25 4
gpt4 key购买 nike

我写了一个表格组件:

<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

最佳答案

我必须改变:

<tablesample data="tableData" model="selectedRow" edit="editFunction()"></tablesample>

至:

<tablesample data="tableData" model="selectedRow" edit="editFunction(id,a)"></tablesample>

谢谢文档穆尔

关于javascript - AngularJS 组件 - 函数绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47359162/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com