Reputation: 46909
In the following code i get a type error as
Type error:Cannot read property 'GET()' of undefined
what ami doing wrong here
Services
MyApp.factory('Myops', function($resource) {
return $resource('/projects/:ID/releases/', {
ID: "@ID"
}, {
"update": {
method: "PUT"
},
"create": {
method: "POST"
},
"get": {
method: "GET"
}
});
});
Controller
MyApp.controller("psCtrls", ['$scope', 'Myops', function($scope, Myops) {
myops = Myops.GET()
console.log(myops);
}]);
update 1:
After the inclusion of My ops this is the error
Error:[$injector:unpr ] Unknown provider :$resource provider<-$resource<-Myops
Upvotes: 1
Views: 1166
Reputation: 136144
There is Myops
dependency not injected properly
MyApp.controller("psCtrls",['$scope', 'Myops', function($scope,Myops){
}]);
Update 1:
include angular-resource.js
then include the required dependency in your app in order to use $resource
service
var app = angular.module('myApp',['ngResouce']);
Update 2
Your resource get call should be .get
instead of .GET()
Myops.get().then(function(data){
console.log(data);
})
Upvotes: 3
Reputation: 15239
You need to include your Myops
service as following:
MyApp.controller("psCtrls",['$scope', 'Myops',function($scope,Myops)
{
myops = Myops.GET()
console.log(myops);
}]);
Based on your updated question: it seems like you didn't include ngResource
in your application, it didn't come with AngularJs. So, you need to manually include it:
<script src="angular-resource.js">
Using:
//ajax.googleapis.com/ajax/libs/angularjs/X.Y.Z/angular-resource.js
bower install angular-resource
Then, inject it in your app:
angular.module('app', ['ngResource']);
Upvotes: 2
Reputation: 1502
Myops is not being injected. Change it to
...
MyApp.controller("psCtrls",['$scope', 'Myops', function($scope,Myops)
...
Upvotes: 1