$uibModal close($value) 回调总是返回 undefined

Jef*_*aal 2 javascript angularjs angular-ui-bootstrap

从我的模板中,我ng-click="$widget.addItem()"用来触发$uibModal.

一切正常,打开,关闭等。

问题是,我无法让$modal.close($value)回调值起作用。该函数本身工作正常,模态关闭,并调用 promise 成功函数。问题是,它总是返回undefined.


组件控制器

app.component('list', {
    templateUrl: 'widgets/list.html',
    controllerAs: '$widget',
    controller: function($uibModal) {

        // Add item through modal
        this.addItem = function() {

            // Init and open $uibModal
            var modalInstance = $uibModal.open({
                component   : 'modalAddItem',
                size        : 'md'
            });

            // $uibModal promise
            modalInstance.result.then(function(params) {
                console.log(params)
                // ---> undefined 
            });
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

模态模板

<div class="modal-add-item">

    <div class="modal-body" id="modal-body">
        // Some template stuff here 
    </div>

    <div class="modal-footer">
        <button class="btn btn-sm btn-default" ng-click="$modal.ok()">Ok</button>
    </div>

</div>
Run Code Online (Sandbox Code Playgroud)

模态组件

app.component('modalAddItem', {
    templateUrl: 'widgets/modals/add-item.html',
    bindings: {
        resolve: '<',
        close: '&',
        dismiss: '&'
    },
    controllerAs: '$modal',
    controller: function ($scope) {

        this.ok = function() {
            this.close({item: 'picked item'});
        }

    }
});
Run Code Online (Sandbox Code Playgroud)

一切正常。但无论我尝试什么,关闭函数总是返回undefined

Kar*_*rim 5

你应该使用$value而不是项目。

this.ok = function() {
  this.close({$value: 'picked item'});
}
Run Code Online (Sandbox Code Playgroud)

close - 一种可用于关闭模态并传递结果的方法。结果必须以这种格式传递:{$value: myResult}

Angular UI 引导程序