我正在尝试使用bootstrap中的模态类创建一个弹出窗口,我收到以下错误 - TypeError:无法读取未定义的属性“open”
angular.module('storagewebApp').controller('controller',['$scope','$modal', function($scope,$modal) {
$scope.threshold = [];
$scope.open = function(){
var modalInstance = $modal.open({
animation: true,
templateUrl: 'views/view1.html',
controller: 'controller2',
resolve: {
items: function(){
return $scope.threshold;
}
}
});
modalInstance.result.then(function (changed_threshold){
$scope.threshold = changed_threshold;
});
};
}]);
angular.module('storagewebApp').controller('controller2',function($scope, $modalInstance, items) {
$scope.threshold = items;
$scope.selected = [];
$scope.ok = function(){
$modalInstance.close();
};
$scope.cancel = function(){
$modalInstance.dismiss('cancel');
}
});
我有单独的app.js,其中包含所有服务 -
angular.module('storagewebApp', [
'ngMessages',
'ngRoute',
'ngSanitize','ui.select', 'ui.bootstrap'])
.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/view.html',
controller: 'controller'
})
.otherwise({
redirectTo: '/'
});
});
以下是我得到的错误:
TypeError: Cannot read property 'open' of undefined
at Scope.$scope.open (http://unixdeva16.factset.com/~sokumar/www/stud/app/scripts/controllers/controller.js:804:29)
at fn (eval at <anonymous> (http://unixdeva16.factset.com/~sokumar/www/stud/app/bower_components/angular/angular.js:13036:15), <anonymous>:2:203)
at callback (http://unixdeva16.factset.com/~sokumar/www/stud/app/bower_components/angular/angular.js:23090:17)
at Scope.$eval (http://unixdeva16.factset.com/~sokumar/www/stud/app/bower_components/angular/angular.js:15719:28)
at Scope.$apply (http://unixdeva16.factset.com/~sokumar/www/stud/app/bower_components/angular/angular.js:15818:23)
at HTMLButtonElement.<anonymous> (http://unixdeva16.factset.com/~sokumar/www/stud/app/bower_components/angular/angular.js:23095:23)
at HTMLButtonElement.n.event.dispatch (http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js:3:6404)
at HTMLButtonElement.r.handle (http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js:3:3179)(anonymous function) @ angular.js:12221
答案 0 :(得分:0)
显然,您的应用中未包含myEnum
服务,请尝试:
modal
我不确定该模块是否为“ui.bootstrap”,将其添加到您的应用程序或包含 angular.module('storagewebApp', ['ui.bootstrap'])...
的模块名称
在这个带有示例结构的“plnkr”中,我没有看到任何错误:http://plnkr.co/edit/nNJrobGAt5mdUzLiuGk8?p=preview