8

Trying to learn AngulareJS got stuck with this.

This is the code :

app.config(function ($routeProvider){
$routeProvider
.when('/',
{       
    templateUrl: '/sort',
    controller : 'tasksController'      
})  
.when('/expression/:expressionId/type/:typeId',
{   
    templateUrl: '/sort/'+:expressionId +'/'+ :typeId,
    controller : 'tasksController'  
})});

This is obviously wrong.

Can any one please tell me what is the correct way to do this? Thanks.

3
  • Perhaps you should tell us why it is wrong. What is the behavior you are getting? Commented May 17, 2014 at 16:43
  • The way you're trying to approach it is not possible with Angular's "native" router. It is, however, possible with Angular UI Router. If you wanted to stick with ngRouter, you could use a combination of $routeParams (populated within a controller), and ngInclude within your main view. Commented May 17, 2014 at 20:01
  • I figured it out.Thank you for your response. Commented May 17, 2014 at 20:38

2 Answers 2

14

Thanks guys,this is what I wanted

.when('/expression/:expressionId/type/:typeId', {

templateUrl: function(params) {
    return '/sort/' + params.expressionId +'/'+ params.typeId ;
},
controller: 'tasksController'
});
Sign up to request clarification or add additional context in comments.

1 Comment

I know it is a bit late to comment here, but, can you explain where are you passing 'params', where params get its value from?! Thanks.
1

Probably you are looking for $routeparams https://docs.angularjs.org/api/ngRoute/service/$routeParams.

you can do something like below:

app.config(function ($routeProvider){
  $routeProvider
    .when('/',{
        templateUrl: '/sort',
        controller : 'tasksController'
    })
    .when('/expression/:expressionId/type/:typeId', {
        templateUrl: '/sort',
        controller : 'tasksController'
    })
});

app.controller('tasksController', ['$scope', '$routeparams', function($scope, $routeparams) {
    var expressionId = $routeparams.expressionId
        , typeId = $routeparams.typeId;
}]);

1 Comment

I figured it out.Thank you for your response.

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.