Typescript Angular ui bootstrap modal

Typescript Angular ui bootstrap modal

本文关键字:modal bootstrap ui Angular Typescript      更新时间:2023-09-26

我使用angular.ui.bootstrap模态来显示模态中的表单。一切都很好,除了当我关闭模态时,我想在父页面上的一个表被更新与模态中添加的新项目。

父控制器:

module MyApp.Controllers {
export interface IController {
    items: Models.IItem[];
}
export interface IControllerScope {
}
export class Controller implements IController {
    items: Models.IItem[];
    constructor(
        private $scope: IControllerScope,
        private $modal: ng.ui.bootstrap.IModalService) {
    }
    addItem() {
        var options: ng.ui.bootstrap.IModalSettings = {
            templateUrl: '/directives/formFirective',
            controller: 'formController',
            controllerAs: 'modal',
            resolve: {
                id: () => 1234
            }
        };
        this.$modal.open(options).result
            .then(function (item) {
                // How do I add item to the instance variable items here?
                this.items.push(item) // Does not work here :(
                console.log(item)
            });
    }
}

}

然后在formController中我有:
this.$modalInstance.close(item);

我的问题是如何将项目添加到父控制器上的实例变量项目上的模态关闭?

谢谢。

尝试更改=>

function (item) {
                // How do I add item to the instance variable items here?
                this.items.push(item) // Does not work here :(
                console.log(item)
            }
在:

(item) => {
                // How do I add item to the instance variable items here?
                this.items.push(item) // Does not work here :(
                console.log(item)
            }