对话框关闭后在Controller上调用方法

时间:2013-07-15 20:19:54

标签: angularjs angularjs-scope angular-ui

我正在尝试打开一个对话框,用户可以在其中输入名称,然后在控制器上调用方法从对话框中传递结果。

class MyController {

    constructor(public $scope, public $dialog) {
    }

    AddNew() {

        var t = '<form name="form" novalidate><div class="modal-header">' +
          '<h3>Nova mapa</h3>' +
          '</div>' +
          '<div class="modal-body">' +
          '<p>Name: <input ng-model="result" type="text" required/></p>' +
          '</div>' +
          '<div class="modal-footer">' +
          '<button ng-click="close()" class="btn btn-primary" >Close</button>' +
          '<button ng-click="close(result)" class="btn btn-primary" ng-disabled="form.$invalid">Save</button>' +
          '</div><form>';

        this.$scope.opts = {
            backdropClick: false,
            template: t,
            controller: 'AddNewDialog'
        };


        var d = this.$dialog.dialog(this.$scope.opts);
        d.open().then(function (result) {
            if (result) {
                // this does not work 
                this.AddNewInternal(result)
            }
        });
    }

    private AddNewInternal(description: string) {
        //logic here

    };
}

function AddNewDialog
    ($scope, dialog) {
    $scope.close = () => {
        $scope.close(undefined);
    }
    $scope.close = (result) => {
        dialog.close(result);
    };
}

我收到错误“对象不支持属性或方法'AddNewInternal'” 有人可以帮我解决这个问题吗? 谢谢

0 个答案:

没有答案