0

I have developed a form builder where User(admin) can add (create) a new page, and then assign an URL for that page.

I am stuck while mapping Url of these dynamically created pages, as I can not loop through the Urls. I have to use this when(which is something like if, else). like

var dunamicUrl = 'UserAssignedUrl';
var somevar = dunamicUrl+".html"; // I create view with same name as
//Url given by user for new created page

function config($routeProvider, $locationProvider)
{
    $routeProvider
        .when('/'+dunamicUrl, {
            controller: 'CommonController',
            templateUrl: somevar,
            controllerAs: 'vm'
        }).when('/register', {
            controller: 'RegisterController',
            templateUrl: 'register.html',
            controllerAs: 'vm'
        }).otherwise({ redirectTo: '/login' });
}

But I don't want to hard code Urls for dynamic views, because they could be changed by user. I am trying to get this solution working for me AngularJS dynamic routing

 $routeProvider.when('/page/:name*', {
        templateUrl: function(urlattr){
            return '/pages/' + urlattr.name + '.html';
        },
        controller: 'CMSController'
 });

As a beginner of angular, above solution has some confusions for me, especially how urlattr is set. What will urlattr.name produce?Second, can I replace/page/:name*'with/page/:xyz*'? Do I need to define thisxyz` somewhere else?

Community
  • 1
  • 1
Sami
  • 8,168
  • 9
  • 66
  • 99
  • As the answer says, the urlattr parameter is filled by using `$location.path()` on the current path. As for what `urlattr.name` will produce, why don't you add `console.log()` statements and find it out? – callmekatootie Jul 28 '15 at 05:56
  • It produced undefined. I meant to say how it could be set to get it working. Do you know where to use `$location.path()` I mean how it would set `urlattr` parameter? – Sami Jul 28 '15 at 06:25
  • So if `route parameters extracted from the current $location.path() by applying the current route` means that i dont have to set anywhere, it takes value automatically from current url then, it might be true but its not working fro me till now, I should try more and i would share my code if not works, – Sami Jul 28 '15 at 06:29
  • Thanks it worked, The answer i mentioned has expatiation but sorry not enough for me to understand. You can post in answer relation of `:xyz*` and `urlattr.xyz` and path for the view – Sami Jul 28 '15 at 06:44
  • possible duplicate of [AngularJS dynamic routing](http://stackoverflow.com/questions/13681116/angularjs-dynamic-routing) – callmekatootie Jul 28 '15 at 10:05

0 Answers0