11

I'm working on my first Angular project and currently stuck (again).

My problem is I have two functions that needs to implement in the Angular config.

What I cannot understand is, both of there modules using <angular module>.config, I don't know how to combine these two , because when I read the Angular docs it seems like it gets a name, and a function.

Following is my current code (and these two works individually)

var myApp = angular.module('myApp', ['ui.router'])
    .config(function($stateProvider, $urlRouterProvider){
        $urlRouterProvider.otherwise("/state1");
        $stateProvider
          .state('state1',{
            url: 'state1',
            templateUrl: "../pages/form.html"
          });
          $locationProvider.html5Mode(false);
    });



myApp = angular.module('myApp', ['facebook'])

    .config([
        'FacebookProvider',
        function(FacebookProvider) {
            var myAppId = '<FB app id>';
            FacebookProvider.init(myAppId);}

    ]
)

How can I combine these two functions in to one

var myApp = angular.module('myApp', ['facebook','ui.router']).config(
     facebook functon and ui-route function
 ) 

I have found almost the same SO question here but unfortunately no answer.

1

2 Answers 2

31

Alternatively, you can chain configs to keep things isolated like so

var myApp = angular.module('myApp', ['ui.router','facebook'])
    .config(function($stateProvider, $urlRouterProvider){
       ... state provider config ...
    })
    .config(function(FacebookProvider){
       ... facebook provider config ...
    });

or you could split them right up like so

var myApp = angular.module('myApp', ['ui.router','facebook']);

myApp.config(function($stateProvider, $urlRouterProvider){
  ...
});

myApp.config(function(FacebookProvider){
  ...
});
Sign up to request clarification or add additional context in comments.

2 Comments

I prefer this solution because you could separate the logic out into multiple files.
yes, keeping the logic in separate files feels 'cleaner' to me as it keeps concerns distinct facebook config separate to state provider config
11
var myApp = angular.module('myApp', ['ui.router','facebook'])
    .config(function($stateProvider, $urlRouterProvider, FacebookProvider){
        $urlRouterProvider.otherwise("/state1");
        $stateProvider
          .state('state1',{
            url: 'state1',
            templateUrl: "../pages/form.html"
          });
          $locationProvider.html5Mode(false);

        var myAppId = '<FB app id>';
            FacebookProvider.init(myAppId);
    });

Is that what you want?

4 Comments

Thanks a lot.... I was trying to fix this for last 2 days :)... thanks again... all I had to modify is to add $locationProvider in the same line with $stateProvider :)
@words Like Jared: Hellom I have a similar problem. We have several routing and a othersise condition. Waht can I do? what is the trick?$locationProvider.html5Mode(false);
@AliSaberi If you're still having the issue ask it ask a question and myself or someone else will answer.
thanks. I opened a new question here:stackoverflow.com/questions/33971500/…

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.