I need to pass a variable to $scope in $routeProvider. Code is following:
.when('/:zone/edit/:id', {
templateUrl: 'views/edit.html',
controller: 'EditSet'
})
.when('/articles/edit/:id', {
templateUrl: 'views/edit-article.html',
controller: 'EditSet',
params: {zone: 'articles'}
})
To get param I use $scope.params.zone
, which works in first case (:zone) and does not work in second case.
What should I do in this case?
So I think you might be better off using the function support in templateUrl
to achieve this:
.when('/:zone/edit/:id', {
templateUrl: function(params) {
if (params.zone == "article") {
return 'views/edit-article.html';
}
return 'views/edit.html';
},
controller: 'EditSet'
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With