Reputation: 2154
I'm getting a object is not defined error in an angular application I'm building.
The object that triggers the error is the 'CoffeeOrder' object in the giveMeCoffee function below. The entire source code is in Github.
For what I read in the angular.js documentation, this should work (see code snippet at the bottom). But the error message is not very helpful.
var coffeeApp = angular.module('coffeeApp', ['ngResource']);
coffeeApp.controller('OrderController', function($scope) {
$scope.types = [
{name:'black', family:'coffee'},
{name:'latte', family:'coffee'},
{name:'cappuccino', family:'coffee'},
{name:'tea', family:'other'}
];
$scope.sizes = ['S', 'M', 'L'];
$scope.giveMeCoffee = function() {
CoffeeOrder.save({id: 1}, $scope.drink);
}
});
coffeeApp.factory('CoffeeOrder', function($resource) {
return $resource('/service/coffeeshop/:id/order/', {id: '@coffeeShopId'});
});
Upvotes: 0
Views: 1439
Reputation: 691695
CoffeeOrder
is a service. A service is not a globally available object. It must be injected into other Angular components, and you didn't inject it:
coffeeApp.controller('OrderController', function($scope, CoffeeOrder) {
Upvotes: 1