Angular JS未捕获错误:[$injector:modulerr]未捕获错误

Angular JS Uncaught Error: [$injector:modulerr] uncaught error

本文关键字:错误 modulerr injector Angular JS      更新时间:2023-09-26

我正在使用angular js制作天气预报web应用程序。下面是我的一小段代码。

var myApp = angular.module("myApp", ["ngRoute", "ngResource"]);
myApp.config(function($routeProvider){
$routeProvider
.when('/',{
      templateUrl : 'pages/home.htm',
      controller : 'homeController'
      })
.when('/forecast',{
      templateUrl : 'pages/forecast.htm',
      controller : 'forecastController'
      })
});
myApp.service("cityService", function(){
})

myApp.controller("homeController", ['$scope','cityService', function($scope,cityService){
$scope.city = cityService.city;
$scope.$watch('city', function(){
    cityService.city = $scope.city;
});

}]);

myApp.controller("forecastController", ['$scope','$resource','cityService', function($scope,$resource,cityService){
$scope.city = cityService.city;
$scope.weatherAPI =
    $resource("http://api.openweathermap.org/data/2.5/weather",{
    callback : "JSON_CALLBACK" }, {get : {method : "JSONP" }});
//below is line 41
$scope.weatherResult = $scope.weatherAPI.get({ q: $scope.city, appid: 9fc927759b42ed332b58471398219df0});
console.log($scope.weatherResult);

}]);

我有两个错误:

Uncaught SyntaxError: Unexpected identifier  app.js:41
Uncaught Error: [$injector:modulerr]    angular.js:38 .

我已经添加了所有可能的函数,但仍然会出错。。有人能帮我解决这个问题吗。

此:appid: 9fc927759b42ed332b58471398219df0

应为:appid: '9fc927759b42ed332b58471398219df0'