Reputation: 91
In my app.js , i am configuring my routes to navigate to different controllers with below code
var urlArray=['Suggest','Comment'];
var pdfURL="Suggest";
app.config(function($routeProvider,$locationProvider) {
.when('/datatrial/' +pdfURL, {
templateUrl: 'simple/TestPanelTrial.html',
controller: 'SimpleDemoTrailController'
});});
Currently i am adding variable pdfUrl. I want to add condition that if pdfURL matches to any of the string in urlArray ,then only use the when condition to land into respective controller. the above code resides in app.js which is the first file to get loaded. please inform how can this be acheived.
Upvotes: 0
Views: 35
Reputation: 2926
Instead of a .when()
you'll want a state for this, using a param.
.state('/datatrial', {
url: "/datatrial/:id",
templateUrl: 'simple/TestPanelTrial.html',
controller: function ($stateParams) {
if ($state.params.id !== 'Suggest') {
$state.go('/error');
}
}
});
This is untested, but I believe it will work. Transversely, you could put that function in your controller, since I see you link to one in your question, but I put it in like I did for brevity.
Upvotes: 1