1

This is my service:

    app.factory('ApiStoreService', function ($q) {

        return $q(function (resolve, reject) {

            new SwaggerApi({
                discoveryUrl: "https://apiurl",
                apiKeyName : "apiKey",
                apiKey: "xxxxxxxxx",
                success: function () {
                    resolve(this);
                }
            });
        }) 
    });

which I call this way:

ApiStoreService.then(function (store) {// do something with store}

I want to pass the hardcoded values as parameters. What's the best way to achieve this in angular?

Cœur
  • 34,719
  • 24
  • 185
  • 251
Artur Stary
  • 690
  • 1
  • 13
  • 30
  • 1
    Create an object with some functions on it and return that object from factory. That way you can pass parameters. – Chandermani Apr 09 '15 at 10:20
  • This post might give you a clue - http://stackoverflow.com/questions/22561989/angularjs-factory-parameter – Chris Apr 09 '15 at 10:30

2 Answers2

1
    app.factory('ApiStoreService', function ($q) {
    return{
        DoFunction: function(value){
            return $q(function (resolve, reject) {

                new SwaggerApi({
                    discoveryUrl: "https://apiurl",
                    apiKeyName : "apiKey",
                    apiKey: "xxxxxxxxx",
                    success: function () {
                        resolve(this);
                    }
                });
            })
        }
    }
});

and use it like this:

var Obj = { name:'tim'};
ApiStoreService.DoFunction(Obj);
Dominic Scanlan
  • 989
  • 1
  • 5
  • 12
0

I guess Angular Constants/Value would serve the purpose and please read the below gist, https://gist.github.com/demisx/9605099

reflexdemon
  • 636
  • 7
  • 19