我在构建的角度应用程序中没有定义对象的错误。
触发错误的对象是' CoffeeOrder'下面的giveMeCoffee函数中的对象。整个源代码位于Github。
对于我在angular.js documentation中阅读的内容,这应该有效(请参阅底部的代码段)。但错误信息不是很有帮助。
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'});
});
答案 0 :(得分:1)
CoffeeOrder
是一项服务。服务不是全局可用的对象。它必须注入其他Angular组件,而你没有注入它:
coffeeApp.controller('OrderController', function($scope, CoffeeOrder) {