0

I have 3 urls(blog, help, tips) for routing which will be having same controller and same html page.

rcapp.config(function($routeProvider) {

    $routeProvider

    .when('/csv-validation',{

        templateUrl:'csv-validation.html',
        controller:'csvController'
    })
    .when('/blog',{

        templateUrl:'blog_tips.html',
        controller:'blogTipsController'
    })
    .when('/tips',{

        templateUrl:'blog_tips.html',
        controller:'blogTipsController'
    })
    .when('/help',{

        templateUrl:'blog_tips.html',
        controller:'blogTipsController'
    })
});

can i do it in one .when condition for those 3 urls.

2
  • You mean, a single page, but have three links as blog, tips, help Commented Feb 12, 2016 at 11:50
  • yes i mean i want to write only one .when condition that will check if the url link is among those three(blog, help, tips) @rroxysam Commented Feb 12, 2016 at 12:01

1 Answer 1

2

Not a single .when, but you can put it in a loop:

rcapp.config(function($routeProvider) {

    var rp = $routeProvider

    .when('/csv-validation',{

        templateUrl:'csv-validation.html',
        controller:'csvController'
    });

    angular.forEach(['/blog', '/tips', '/help'],
       function(path) { rp = rp.when(path, {
               templateUrl:'blog_tips.html',
               controller:'blogTipsController'
           });
       });
});

Or I think you could use array.reduce:

['/blog', '/tips', '/help'].reduce(function(rp, path) {
    return rp.when(path, {
        templateUrl:'blog_tips.html',
        controller:'blogTipsController'
    });
}, rp);
Sign up to request clarification or add additional context in comments.

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.