我有两个控制器作为menucontroller和ordercontroller。我从菜单中传递数据以确定其正常,但在传递相同数据时,它会添加一行而不是增加数量。
我有一些名称,价格,数量等值。
答案 0 :(得分:0)
您应该考虑使用provider(服务或工厂)在控制器之间共享数据。请考虑以下示例:
// shared factory
angular.module('myApp').factory('myFactory', myFactory);
// anything exposed by this factory will be available
// to any controller that injects it
function myFactory() {
var factory = this;
factory.menu = {food: {}, etc: []};
factory.method = someMethod;
return factory;
function someMethod() { ... }
}
// Controller Example
angular.module('myApp').controller('myController', myController);
function myController(myFactory) {
var menu = myFactory.menu; // exposed by our factory and is available
myFactory.someMethod();
}