我正在使用角度bootstrap ui模态,它工作正常,但是当我尝试使用modalInstance关闭它时,出现上述错误。这是我的代码
var app = angular.module('LoginModule', ['ui.bootstrap']);
app.controller('LoginModal', ['$scope', '$modal', function ($scope, $modal) {
$scope.animationsEnabled = true;
$scope.open = function (size) {
var modalInstance = $modal.open({
animation: $scope.animationsEnabled,
templateUrl: '/app/template/Login.html',
controller: 'LoginController',
size: size
});
}
}]);
app.controller('LoginController', ['$scope', '$modalInstance', '$http', function ($scope, $modalInstance, $http) {
$scope.model = {};
$scope.loading = {
state: false
}
$scope.errors = '';
$scope.email = "";
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
}]);
我已经在控制器中创建了cancel函数,并使用模板指定了该函数,但仍然会出错。我在LoginController的按钮中使用ng-click =“ cancel()”。需要帮忙?
看起来您正在模态视图中使用ng-controller指令实例化控制器。取而代之的是,您只需要使用controller
模式选项就可以$modalInstance
注入特殊的依赖项。如果使用了实例化控制器ng-controller="LoginController"
,则需要将其删除,并且不需要它,因为控制器将被自动实例化(通过解决特殊依赖关系$modalInstance
)并附加到模板上。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句