user3378347
user3378347

Reputation: 1

AngularJS simple Factory related error

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();
});

Error It shows : Error: [$injector:unpr] http://errors.angularjs.org/1.2.14/$injector/unpr?p0=simpleFactoryProvider%20%3C-impleFactory at Error (native)

Upvotes: 0

Views: 169

Answers (2)

Algimantas Krasauskas
Algimantas Krasauskas

Reputation: 403

Hy, I made a plunker so you could see into how it should work: Plunker LINK, because I think you will run in to some other stuff too. Stuff that I found to be wrong in the code that you provided:

  • demoApp.factory = ('simpleFactory', function(){...}), should be demoApp.factory('simpleFactory', function () {...}) - because you are calling a method, not providing one.
  • If you want to put a comment, you should use // or /* comment for multiple lines */, not just put 'string'
  • Also if you provide private variables, you should keep their names different, like '_customers', it's a small thing, but it will help other people to understand what is your intention.

Upvotes: 1

JB Nizet
JB Nizet

Reputation: 691913

demoApp.factory = ('simpleFactory', function () {

should be

demoApp.factory('simpleFactory', function () {

Upvotes: 1

Related Questions