我在控制台中遇到了一些问题,我不确定如何修复。
我得到的第一个错误是
angular.js:68未捕捉错误:[$ injector:nomod]模块' reviewsApp'是 无法使用!您要么错误拼写了模块名称,要么忘记加载 它。如果注册模块,请确保指定依赖项 作为第二个论点。
以及......
angular.js:68未捕获错误:[$ injector:modulerr]失败 实例化模块reviewsApp由于:错误:[$ injector:nomod]模块 ' reviewsApp'不可用!您要么错误拼写了模块名称 或者忘了加载它。如果注册模块,请确保指定 依赖关系作为第二个参数。
有人可以告诉我做错了吗?
我有一个简单的控制器,如下所示,底部是html(请不要将这些文件在我的项目中分开)...
(function() {
'use strict';
angular
.module('reviewsApp')
.controller('ReviewsController', ReviewsController);
ReviewsController.$inject = ['$http'];
function ReviewsController ($http){
var vm = this;
var onReviewComplete = function(response) {
vm.reviews = response.data;
};
var onError = function(reason) {
vm.error = reason.data;
};
$http.get('../DataService/services/reviews/getReviews.php')
.then(onReviewComplete, onError);
//Insert Review
vm.insertReview = function(review){
//Create review object.
var reviewObj = {
'name' : review.name,
'message' : review.message
};
var insertRequest = $http.post('xxnx.com', reviewObj);
insertRequest.success(function(data, status, headers, config) {
vm.showSuccessAlert = true;
vm.clearForm(review)
});
insertRequest.error(function(data, status, headers, config) {
vm.showFailAlert = true;
});
};
vm.clearForm = function (review){
review.name = "";
review.message = "";
};
}
})();
<div class='container-fluid' ng-app='reviewsApp' ng-controller='ReviewsController'>
<div class='container'>
<div class='row'>
<h1 class='col-md-12 review-main-heading'> Reviews </h1>
</div>
<div class='row'>
<div class='col-md-9'>
答案 0 :(得分:1)
您还需要添加[]
来提及依赖项,
更改
发件人强>
angular.module('reviewsApp')
.controller('ReviewsController', ReviewsController);
要强>
angular.module('reviewsApp',[])
.controller('ReviewsController', ReviewsController);
答案 1 :(得分:1)
试试这样:
var reviewsApp = angular.module('reviewsApp',[]);
reviewsApp.controller('ReviewsController',['$scope', '$http' function($scope, $http) {
// Your own code which is in - "function ReviewsController(){}" - comes here
}]);