When I try to call the query() function using ngResource, I keep getting an error message saying "Undefined is not a function."
[demo.js]
var app = angular.module('StarterApp', ['ngResource']);
app.factory("resourceFactory", function($resource) {
return $resource("js/demo2.json", {}, {
'get':{method:'GET'},
'query':{method:'GET',isArray:true,url:"js/demo2.json"},
'save':{method:'POST'}
});
});
app.controller('appCtrl', function($scope, resourceFactory){
'use strict';
var ajax = new resourceFactory;
ajax.$query(function(response) {
console.log(response);
});
});
[demo2.json]
[
{"demo2":"test"}
]
[error]
TypeError: undefined is not a function
at http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular-resource.min.js:9:466
at s (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:7:302)
at d.module.provider.$get.e.(anonymous function).q.then.p.$resolved (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular-resource.min.js:9:423)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:112:20
at l.$get.l.$eval (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:125:305)
at l.$get.l.$digest (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:122:398)
at l.$get.l.$apply (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:126:58)
at l (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:81:171)
at S (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:85:301)
at XMLHttpRequest.D.onload (http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js:86:315)
When I use "$get" with a simple object return, everything works fine. I'm confused about what could be wrong with my code.