0
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)

2 Answers 2

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

should be

demoApp.factory('simpleFactory', function () {
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.