javascript - Typescript Angular ui 引导模式

标签 javascript angularjs typescript

我正在使用 angular.ui.bootstrap 模态在模态中显示表单。一切正常,除了当我关闭模态时,我希望父页面上的表格使用模态中添加的新项目进行更新。

我的父 Controller :

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

我的问题是如何在模式关闭时将项目添加到父 Controller 上的实例变量项目?

谢谢。

最佳答案

尝试改变=>

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

关于javascript - Typescript Angular ui 引导模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32386932/

相关文章:

javascript - 如何聚合 Node.js 流回调中异步函数生成的 Promise?

javascript - Ionic2 - 根据 Controller 的显示方式显示/隐藏按钮

java - 在 WebView 在线表单中填写没有 id 的文本字段

php - 任何方法都可以知道页面是否是通过 AJAX 调用的

javascript - 一些实用函数的通用类型

javascript - 如何修改只读值?

javascript - 在 ES6 中导入常量的正确语法

javascript - 使用 Angular js 从日期时间中提取时间

ios - Ionic ios 模拟器不加载谷歌地图

html - 以 Angular 注入(inject) $modal 时出错