我正在尝试将模型传递给ngDialog模板

可编辑表格

<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);
            });
        }]
    })
};


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

最佳答案

您需要使用resolve将数据传递给modal:

 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

10-04 22:12