1

I am new to angularJS and trying to learn it. I came across config function where I see two different arguments as in below example.

Example 1

dashboardApp.config(function($stateProvider, $urlRouterProvider) {
//$urlRouterProvider.when('', '/add');
$stateProvider.state('add', 
                 { 
                     url:'/add?month&year', 
                     templateUrl: 'partial/add.html', 
                     controller: 'AddListController' 
                 })
});

Example 2

gm.config(['$routeProvider', 'Path', function($routeProvider, Path) {
$routeProvider.when('/login', { 
    templateUrl: Path.view('application/authentication/login.html'), 
    controller: 'authController' 
});
}]);

In the first example, config has a function parameter. And in second example config has array parameter.

Can someone please explain to me what is the difference between these two approaches and when to use which?

3

3 Answers 3

0

There are two differences here. The first example is providing configuration for Angular UI Router, whereas the second is using ngRoute.

The difference in syntax that you noted is the difference between having code that will not withstand minification (first example) and code that will withstand minification.

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

Comments

0

+1 to the previous answer pointing out $stateProvider is angular ui-router syntax. I would also point out that declaring $routeProvider has different syntax than other angular items like services and controllers.

Comments

0

You should use ui-route provider as it is better than ngRoute, ui-router allows you to code your templates in a nested form

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.