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 this
xyz` somewhere else?