我想在angularjs中使用工厂,但它在页面上什么也没有显示,控制台上没有显示任何错误。Angularjs中的工厂不工作
任何人都可以指出我犯的错误吗?
var app = angular.module('myApp',[]);
app.factory('customersFactory',function($scope){
var customers = [{
id:1,
name: 'James',
city: 'Seattle',
orderTotal: 9.546,
joined: '2012-02-05',
orders:[{
id:1,
product:'Shoes',
total:9.9665
}]
}, {
id:2,
name: 'Sarah',
city: 'Dallas',
orderTotal: 3.653,
joined: '2010-08-07',
orders:[{
id:2,
product:'Sandal',
total:8.3465
}]
}, {
id:3,
name: 'Tom',
city: 'Troy',
orderTotal: 8.346,
joined: '2011-04-09',
orders:[{
id:3,
product:'Sneakers',
total:6.3427
}]
}, {
id:4,
name: 'Ling',
city: 'Columbus',
orderTotal: 5.549,
joined: '2014-03-10',
orders:[{
id:4,
product:'belt',
total:8.9674
}]
}];
var factory={};
factory.getCustomers = function(){
return customers;
};
factory.getCustomer = function(customerId){
for (var i = 0, len = customers.length; i < len; i++) {
if (customers[i].id === parseInt(customerId)) {
return customers[i];
}
}
return {};
}
return factory;
});
我如何测试型动物路线成plunker?其实你的是空的。路由不是在做他的工作。 –
Okazari