【发布时间】:2015-08-18 05:26:12
【问题描述】:
我正在尝试使用 Angular js 中的模态创建一个 POP UP。我正面临着问题。它说。
TypeError:无法读取未定义的属性“打开”。 它抛出 $modal.open 语句。
配置代码如下:
homeModuleApp.config(function ($stateProvider) {
$stateProvider.state('login', {
url: '/login',
//templateUrl: '/app/ng/modules/home/partials/login-partials-view.html',
//controller: 'ModalDemoCtrl'
onEnter: function($stateParams, $state, $modal) {
$modal.open({
templateUrl: '/app/ng/modules/home/partials/login-partials-view.html',
resolve: {},
controller: 'ModalDemoCtrl'
}).result.then(function (result) {
// $scope.$close
alert('result ->' + result);
}, function (result) {
// $scope.$dismiss
alert('dismiss ->' + result);
}).finally(function () {
// handle finally
console.log('Hello....');
});
}
})
});
谁能指导我可能是什么问题?
谢谢
【问题讨论】:
-
好吧,如果你得到“未定义”错误,你必须问自己为什么它是未定义的,它应该是什么。在您的代码中,您只需注入 $modal,但 $modal 是什么? angular 默认没有 $modal,你有注入 $modal service/factory 的 angular 模块吗?
-
你还没有注入它(就像你注入了
$stateProvider);但是,由于它是一项服务,因此在module.config()部分时将不可用。另外,不同的汤姆 :) -
@Tom 感谢您的回复。我是 Angular 新手,您能帮我实现同样的方法吗?
标签: angularjs node.js angular-ui-router angular-ui-bootstrap