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)
我也查了一下,但我的其他問題無法解決問題。
感謝的人。正在讓我發瘋。將接受。 – norbertpy 2015-02-07 20:39:42
歡迎您! – dfsq 2015-02-07 20:41:05