错误:$ injector:modulerr AngularJS

时间:2016-01-30 06:19:53

标签: javascript angularjs

我知道这个主题已经发布了很多但是没有一个解决方案似乎特定于我的问题。我在" .service"开头的行上收到错误。在检查员中它只是说,"意外的令牌。"好像它不喜欢这个时期。在该行之后它有$ injector:modulerr错误。有什么建议? (我没有包含json文件,因为它只是一个对象数组)。

JS

{
  "rules": {
          // Only authenticated user can read
          ".read": "auth != null",
          // Only authenticated user can write
          ".write": "auth != null",
     }
}

1 个答案:

答案 0 :(得分:1)

您在控制器中放置了一个半冒号,因此这是一个javascript语法错误。

应该是这样的:

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)
    }
});

希望它有所帮助。