Sal*_*leh 5 javascript angularjs angular-ui angular-ui-bootstrap
我一直在玩这个错误,但我似乎无法弄清楚。当我推送我添加到 prod 服务器的 angular-bootstrap 模型时,问题就开始了。原来的错误是这样的:
“AngularJS 错误:未知提供者:aProvider <- a”
我很确定我收到了那个错误,因为我的文件没有正确缩小。所以我浏览了我的控制器,发现我没有$injecting $modal实例到我的控制器中,那是我遇到这个问题的时候。
每当我$modalInstance以缩小格式注入我的控制器时,我都会收到此错误。我没有使用 angular-bootstrap 建议的格式,因为我有很多事情要做,而且我正在构建的站点上有很多控制器,所以我将所有东西组合成一个控制器,而不是几个功能。
我的控制器:
.controller('CreateGroupCtrl', ['$scope', '$http', '$window', '$cookies', '$modal', '$log', 'FeedService', '$modalInstance',
function CreateGroupCtrl($scope, $http, $window, $cookies, $modal, $log, $modalInstance, FeedService) {
$scope.createGroupCall = function createGroupCall(teacher, name) {
if(teacher != null && name != null) {
FeedService.createGroupCall($cookies.token, $window.sessionStorage.user, teacher, name).success(function(data) {
console.log('GroupCreated');
}).error (function(status,data,token) {
console.log(status);
console.log(data);
});
} else {
alert("Error!");
}
}
/***********ANGULAR-UI MODAL CODE**********/
$scope.open = function (size) {
var modalInstance = $modal.open({
templateUrl: 'CreateGroupContent.html',
controller: CreateGroupCtrl,
size: size
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem;
}, function () {
$log.info('Modal dismissed at: ' + new Date());
});
};
$scope.ok = function () {
$modalInstance.close();
};
$scope.cancel = function () {
$modalInstance.dismiss('cancel');
};
}]);
Run Code Online (Sandbox Code Playgroud)
我的模板:
<button ng-controller="CreateGroupCtrl" ng-click="open()" type="button" id="creategroup" class="btn ns-btn">
<img class="ns-add" src="images/createGroup.png">
<p class="create">Create Group</p>
</button>
<div>
<script type="text/ng-template" id="CreateGroupContent.html">
<div class="modal-header">
<h2 class="modal-title ns-modal-title">Create A Group</h2>
<button class="ns-modal-close" ng-click="cancel()"><img src="images/xCancel.png"></button>
</div>
<div class="modal-body">
<form class="form-signin" role="form">
<input type="text" class="form-control ns-modal-form" placeholder="Teacher" ng-model="create.teacher" required autofocus>
<input type="text" class="form-control ns-modal-form" placeholder="Group Name" ng-model="create.name" required>
</form>
</div>
<div class="modal-footer">
<button class="btn ns-modal-add ns-btn" ng-click="createGroupCall(create.teacher, create.name); ok();" type="submit">Create</button>
</div>
</div>
</script>
</div>
Run Code Online (Sandbox Code Playgroud)
首先,您需要按顺序注入所有内容。
此外,您应该注入要$modal在其中创建模态视图的控制器。而$modalInstance可注入ONLY成用于此控制器$modal窗口。在您的情况下,您使用相同的控制器,因此您无法注入$modalInstance
此外,在您的情况下(当您仅使用 1 个控制器时)-您可以作为对象字段传递,scope该字段将用作$scope模态视图的父级。默认情况下它是$rootScope,但您可以键入:
$scope.open = function (size) {
var modalInstance = $modal.open({
templateUrl: 'CreateGroupContent.html',
controller: CreateGroupCtrl,
size: size,
scope: $scope
});
Run Code Online (Sandbox Code Playgroud)
所以现在您的函数ok()和cancel()将在您的模态视图和模态范围中可用。
| 归档时间: |
|
| 查看次数: |
4471 次 |
| 最近记录: |