【问题标题】:AngularJS Component - Function BindingAngularJS 组件 - 函数绑定
【发布时间】: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


    【解决方案1】:

    我不得不改变:

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

    到:

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

    谢谢 文档

    【讨论】:

      猜你喜欢
      • 2020-03-21
      • 2016-12-12
      • 1970-01-01
      • 2019-02-09
      • 1970-01-01
      • 2017-06-17
      • 2017-01-08
      • 2014-04-21
      • 2016-12-24
      相关资源
      最近更新 更多