简体   繁体   English

错误:$ injector:modulerr AngularJS

[英]Error: $injector:modulerr AngularJS

I know this subject has been posted a lot but none of the solutions seem to be specific to my problem. 我知道这个问题已经发表了很多,但是没有一种解决方案似乎是我的问题所特有的。 I'm getting an error on the line that begins with ".service". 我在以“ .service”开头的行上遇到错误。 In the inspector it just says, "unexpected token ." 在检查器中,它只是说“意外令牌”。 as if it didn't like the period. 好像不喜欢那个时期。 After that line it has the $injector:modulerr error. 该行之后出现$ injector:modulerr错误。 Any suggestions? 有什么建议么? (I didn't include the json file because it's just an array of objects). (我没有包括json文件,因为它只是一个对象数组)。

JS JS

angular.module("powerpotApp", [])

.controller('mainCtrl', function($scope, dataService) {

    dataService.getPlants(function(response) {
        $scope.plants = response.data;
    });
});

.service('dataService', function($http) {

    this.getPlants = function(callback) {
        $http.get('mock/plants.json').then(callback)
    }
});

You have put a semi colon at your controller so it is a javascript syntax error. 您在控制器上加了分号,这是一个JavaScript语法错误。

It should be like this: 应该是这样的:

angular.module("powerpotApp", [])

.controller('mainCtrl', function($scope, dataService) {

    dataService.getPlants(function(response) {
        $scope.plants = response.data;
    });
})   // removed semi colon here

.service('dataService', function($http) {

    this.getPlants = function(callback) {
        $http.get('mock/plants.json').then(callback)
    }
});

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM