在angularJs文件中使用strict strict命令时出错

时间:2015-08-14 16:20:42

标签: javascript angularjs

我的代码出了什么问题?我不会理解。我做了所有事情就像在this guide中一样: ,但我得Unexpected token ) MainController.js:42

以下是代码:

(function() {
  'use strict';

  angular
  .module('FindItApp')
  .controller('MainController',MainControllerFunction);



  function MainControllerFunction($scope,places){
    angular.extend($scope, {
      mapCenter:{
        lat: 40.741934,
        lng: -74.004897,
        zoom: 16
      },
      layers: {
        baselayers: {
          googleTerrain: {
            name: 'Google Terrain',
            layerType: 'TERRAIN',
            type: 'google'
          },
          googleHybrid: {
            name: 'Google Hybrid',
            layerType: 'HYBRID',
            type: 'google'
          },
          googleRoadmap: {
            name: 'Google Streets',
            layerType: 'ROADMAP',
            type: 'google'
          }
        }
      }
    });

    places.success(function(data){
      $scope.geodata = data;
      $scope.mapMarkers = geodataToMarkers($scope.geodata);
    });
})();

2 个答案:

答案 0 :(得分:1)

因为您错过了该行的}

答案 1 :(得分:0)

您忘记关闭IIFE

的左括号

在第42行中,通过更改

进行修复
})();

}})();

或者,如果您实际修复了代码的缩进,它将如下所示:

(function() {
  'use strict';

  angular
  .module('FindItApp')
  .controller('MainController',MainControllerFunction);

  function MainControllerFunction($scope,places){
    angular.extend($scope, {
      mapCenter:{
        lat: 40.741934,
        lng: -74.004897,
        zoom: 16
      },
      layers: {
        baselayers: {
          googleTerrain: {
            name: 'Google Terrain',
            layerType: 'TERRAIN',
            type: 'google'
          },
          googleHybrid: {
            name: 'Google Hybrid',
            layerType: 'HYBRID',
            type: 'google'
          },
          googleRoadmap: {
            name: 'Google Streets',
            layerType: 'ROADMAP',
            type: 'google'
          }
        }
      }
    });

    places.success(function(data){
      $scope.geodata = data;
      $scope.mapMarkers = geodataToMarkers($scope.geodata);
    });
  } // <-- you previously had this closing bracket in line below, and the following closing bracket was missing.

})();