【发布时间】:2014-09-04 02:00:47
【问题描述】:
我一直在玩这个错误,但我似乎无法弄清楚。当我将添加到产品服务器的 angular-bootstrap 模型推送到产品服务器时,问题就开始了。原来的错误是这样的:
“AngularJS 错误:未知提供者:aProvider
我很确定我收到了这个错误,因为我的文件没有正确缩小。所以我检查了我的控制器,发现我的控制器中没有$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');
};
}]);
我的模板:
<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>
【问题讨论】:
-
在粘贴的示例中,
'FeedService', '$modalInstance'在您比较依赖项和构造函数时被翻转。这是问题中的错字吗? -
不,我就是这么弄的,但我修好了它仍然给我一个错误。
标签: javascript angularjs angular-ui angular-ui-bootstrap