I
I
IvanN7772016-01-17 11:31:41
Angular
IvanN777, 2016-01-17 11:31:41

I don’t fully understand what the when ngRoute router does, does it redirect?

I'm just learning Angular.
But I don't understand what when does

phonecatApp.config(['$routeProvider',
  function($routeProvider) {
    $routeProvider.
      when('/phones', {
        templateUrl: 'partials/phone-list.html',
        controller: 'PhoneListCtrl'
      }).
      when('/phones/:phoneId', {
        templateUrl: 'partials/phone-detail.html',
        controller: 'PhoneDetailCtrl'
      }).
      otherwise({
        redirectTo: '/phones'
      });
  }]);

Are there addresses that it processes and if it does not find a redirect?
We specify the template for the redirect and the controller that will handle it.
I created a link on the site <a href="xxx.localhost/phones"></a>, I go to the page as usual, and if the controller is not specified on it, then angular does not process.
But on idea having followed this link it should apply PhoneListCtrl???

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Io, 2016-01-17
@vawsan

If the url is not in the when list, the code will work

otherwise({
        redirectTo: '/phones'
      });

N
nk_pl, 2016-01-18
@nk_pl

<a href="xxx.localhost/#/phones"></a>
if html5mode is not enabled

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question