【问题标题】:Modal controller not getting resolved模态控制器没有得到解决
【发布时间】:2015-07-31 03:55:57
【问题描述】:

我正在尝试使用 angular/angular-ui-bootstrap 打开一个模态窗口,该窗口非常适合视图,但是相应的控制器似乎没有得到解决,并且 angular 没有吐出任何错误。这里有什么问题?

// calling controller
export class TestController {

    private _modal : angular.ui.bootstrap.IModalService;

    constructor($modal : angular.ui.bootstrap.IModalService) {
        this._modal = $modal;
    }

    edit(myEntity : IEntity) {

        this._modal.open({
            templateUrl: "app/modules/stuff/entity.detail.modal.html",
            controller: "App.Stuff.EntityDetailModalController as modal",
            resolve: {
                item: () => myEntity
            }
        });

    }

}

// modal controller
export class EntityDetailModalController {
    constructor($modalInstance: angular.ui.bootstrap.IModalServiceInstance, item) {
        // ...
    }
}

// controller registration
stuffModule.controller("App.Stuff.EntityDetailModalController", ["$modalInstance", "item", EntityDetailModalController]);

【问题讨论】:

    标签: javascript angularjs twitter-bootstrap angularjs-directive typescript


    【解决方案1】:

    控制器名称应不带“AS”,您可以单独指定控制器别名:

    this._modal.open({
                templateUrl: "app/modules/stuff/entity.detail.modal.html",
                controller: "App.Stuff.EntityDetailModalController",
                controllerAs: "modal",
                resolve: {
                    item: () => myEntity
                }
            });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-11
      • 2013-09-30
      • 2019-07-18
      • 2011-01-14
      • 2022-01-16
      • 2017-12-06
      • 2018-04-15
      • 1970-01-01
      相关资源
      最近更新 更多