2015-02-07 65 views
2

有什么不对这个简单的角度应用:

// app.js 
(function() { 
    'use strict'; 

    angular.module('app', [ 

     'ngRoute', 
     'ngResource', 
     'app.weather' 

    ]) 
     .config(['$routeProvider', function ($routeProvider) { 
      $routeProvider.otherwise({redirectTo: '/'}); 

    }]); 
}()); 

而且控制器和资源:

// weather.js 
(function() { 
    'use strict'; 

    // Resource 
    angular.module('app.weather',['ngResource']) 
     .factory('Entry', function($resource) { 
      return $resource('http://api.openweathermap.org/data/2.5/weather'); 
     }); 

    // Controller 
    angular 
     .module('app.weather') 
     .controller('Weather', Weather); 

    Weather.$inject = ['$resource']; 

    function Weather(Entry) { 
     var vm = this; 
     var result = Entry.get({q: "London,uk"}, function() { 
      vm.data = result; 
      console.log(result); 
     }); 
    } 

}()); 

它提供了以下错误这是指Entry.get({q: "London,uk"}...行:

TypeError: undefined is not a function 
    at new Weather (weather.js:25) 
    at Object.invoke (angular.js:4185) 
    at $get.extend.instance (angular.js:8454) 
    at angular.js:7700 
    at forEach (angular.js:331) 
    at nodeLinkFn (angular.js:7699) 
    at compositeLinkFn (angular.js:7078) 
    at compositeLinkFn (angular.js:7081) 
    at compositeLinkFn (angular.js:7081) 
    at publicLinkFn (angular.js:6957) 

我也查了一下,但我的其他问题无法解决问题。

回答

2

依赖注入是不正确的,你应该注入Entry服务,而不是$resource

Weather.$inject = ['Entry']; 
+0

感谢的人。正在让我发疯。将接受。 – norbertpy 2015-02-07 20:39:42

+0

欢迎您! – dfsq 2015-02-07 20:41:05

相关问题