I am encountering an issue with loading a $resource object in my current scenario.
In the parent controller, I have defined:
$scope.data = Product.$query();
Then, in the child controller:
$scope.data.$promise.then(function(product){
console.log(data);
})
This is how my factory looks like:
angular.module('testApp').factory('Product', ['$resource', function ($resource) {
return $resource('/api/product');
}]);
The reason for placing Product.$query()
in the parent controller is to share it and use it across different child controllers.
My test file setup includes:
describe('Product test ', function () {
var $httpBackend, childCtrl, scope;
beforeEach(module('testApp', function($provide) {
$provide.value('$log', console);
}));
beforeEach(inject(function (_$controller_, _$httpBackend_, _$rootScope_) {
scope = _$rootScope_.$new();
$rootScope = _$rootScope_;
$httpBackend = _$httpBackend_;
childCtrl = _$controller_('childCtrl', {
$scope: scope
});
}));
describe('some test', function() {
it('some test here', function(){
//codes...
})
})
});
However, when running the test, I encounter the error:
TypeError: 'undefined' is not an object (evaluating '$scope.data.$promise')
I am unsure about what might be causing this. Any assistance would be greatly appreciated. Thank you.