1

how to assign a couple of controller and view to multiple route patterns in AngularJS? for example I have a couple of view and controller:

{
  templateUrl: '/partial/single-item.html',
  controller: 'SingleItemController'
}

witch I want them for two routes:

/car/:id
/bike/:id

1 Answer 1

1

You can have a route like : /:myRoute/:id And test in the controller(or in a route regex) the value of myRoute for example

Sign up to request clarification or add additional context in comments.

5 Comments

thanks. But I can't use it. I have too many routes. It makes the routing complicated.
Why do you need to assign all routes to only one controller in fact ?
not all routs. only these two routes. I just want to keep the cod DRY. if fact the example is the exact code I have.
I think you cant make it without repeat it in your configProvider (when('/car/:id', { templateUrl: 'partials/car.html', controller: 'Uniquecontroller' }) etc...)
thanks you. I finaly found a way to use this approach: /:type/:id

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.