将ngTable行输入数据传递给ngDialog输入

时间:2016-02-23 16:13:46

标签: javascript html angularjs ngtable

我试图将模型传递给ngDialog Template

可编辑表格

<table ng-table="tableParams" class="table table-bordered table-striped">
    <tbody>
        <tr ng-repeat="release in releases track by $index">
           <td style="width:5%" data-title="'Version'" ng-model="release.version">{{release.version}}</td>
        </tr>
    </tbody>
</table>

这是打开对话框并调用$ scope.edit

的按钮
<button ng-click="edit(release)" title="Edit" class="btn btn-sm btn-default">

这是ngDialog模板的HTML

        <script type="text/ng-template" id="editRelease">
          <div class="form-group">
            <div class="col-sm-4">
                <input type="text" ng-model="release.version" class="form-control" />
            </div>
          </div>
        </script>

这是我正在尝试填充行的控制器

$scope.edit = function (release) {
    ngDialog.openConfirm({
        template: 'editRelease',
        className: 'ngdialog-theme-default',
        scope: $scope,
        controller: ['$scope', function ($scope) {
            $scope.$watch('release', function (passedObject) {
                console.log(release.version);
            });
        }]
    })
};

我设法从模型中传递对象并将其记录到控制台中。当按下编辑按钮时,如何使用表格中的文本将对话框填充到对话框中?

1 个答案:

答案 0 :(得分:1)

您需要使用解决将数据传递给模态:

 ngDialog.openConfirm({
    template: 'editRelease',
    className: 'ngdialog-theme-default',
    scope: $scope,
    controller: ['$scope','release', function ($scope,release) {
        $scope.$watch('release', function (passedObject) {
            console.log(release.version);
        });
    }],
    resolve: {
        release: function () {
            return release;
        }
    }
})

来源:https://github.com/likeastore/ngDialog#resolve-objectstring-function