var demoApp = angular.module('demoApp', ['ngRoute']);
demoApp.factory = ('simpleFactory', function () {
var factory = {};
var customers = [{ name: 'Touqeer', city: 'Multan' },
{ name: 'Arslan', city: 'RWP' },
{ name: 'Saleem', city: 'Taxila' }];``
factory.getCustomers = function () {
return customers;`enter code here`
};
return factory;
});
demoApp.controller('SimpleController', function ($scope, simpleFactory) {
debugger
$scope.customers = simpleFactory.getCustomers();
});
错误显示: 错误:[$ injector:unpr] http://errors.angularjs.org/1.2.14/ $ injector / unpr?p0 = simpleFactoryProvider%20%3C-implementFactory 在错误(本机)
答案 0 :(得分:1)
demoApp.factory = ('simpleFactory', function () {
应该是
demoApp.factory('simpleFactory', function () {
答案 1 :(得分:1)
Hy,我做了一个plunker,所以你可以看到它应该如何工作:Plunker LINK,因为我认为你也会遇到其他一些东西。我在你提供的代码中发现错误的东西:
demoApp.factory = ('simpleFactory', function(){...})
,应为demoApp.factory('simpleFactory', function () {...})
- ,因为您正在调用方法,而不是提供。//
或/* comment for multiple lines */
,
不仅仅是放置'