0

I have multiple providers in my project and each provider have its own constructor,I am trying to inject all these providers into main app.config. I tried bellow scenario but its not working

tried to add all providers inside the array itself but its not working

app.config([
'EquityValueProvider', function (EquityValueProvider) {
EquityValueProvider.setAPIURL('https://localhost:44333/api/equityvalue');
},
'HeatMapServiceProvider', function (HeatMapServiceProvider) {
HeatMapServiceProvider.setAPIURL('https://localhost:44333/api/equityvalue');
},
'RetailerProvider', function (RetailerProvider) {
RetailerProvider.setAPIURL('https://localhost:44333/api/equityvalue');
}]);

but the bellow code is working (multiple config)

 app.config([
'EquityValueProvider', function (EquityValueProvider) {
EquityValueProvider.setAPIURL('https://localhost:44333/api/equityvalue');
 }])
.config([
'HeatMapServiceProvider', function (HeatMapServiceProvider) {
HeatMapServiceProvider.setAPIURL('https://localhost:44333/api/equityvalue');
}])
.config([
'RetailerProvider', function (RetailerProvider) {
RetailerProvider.setAPIURL('https://localhost:44333/api/equityvalue');
}]);

But here i am adding multiple config,instead of that can i make a single config and add all the providers.

2 Answers 2

1

Provide three arguments to the config function:

app.config([
    'EquityValueProvider','HeatMapServiceProvider','RetailerProvider',   
    function (EquityValueProvider,HeatMapServiceProvider,RetailerProvider) {       
        EquityValueProvider.setAPIURL('https://localhost:44333/api/equityvalue');
        HeatMapServiceProvider.setAPIURL('https://localhost:44333/api/equityvalue');
        RetailerProvider.setAPIURL('https://localhost:44333/api/equityvalue');
    }
]);

For more information, see AngularJS Developer Guide - Dependency Injection.

Sign up to request clarification or add additional context in comments.

Comments

1

Here is how:

app.config([
'EquityValueProvider'
'HeatMapServiceProvider',
'RetailerProvider',
 function (EquityValueProvider, HeatMapServiceProvider, RetailerProvider) {
   EquityValueProvider.setAPIURL('https://localhost:44333/api/equityvalue');
   HeatMapServiceProvider.setAPIURL('https://localhost:44333/api/equityvalue');
   RetailerProvider.setAPIURL('https://localhost:44333/api/equityvalue');
}]);

You can add as many providers as you want.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.