Search code examples
javascriptangularjsangular-resource

Angularjs Type error:Cannot read property 'GET()' of undefined


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

Solution

  • 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);
    })