我正在使用 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/