Angular route when () without matching with controller or pattern

Is it possible to use if () without matching it with any controller or template?

Here's how I set up my routes:

app.config(function($routeProvider, $locationProvider) {
  $locationProvider.html5Mode(true);
  $routeProvider
    .when('/presentations/:id', {});
});

I need to use routeParams in my controller:

app.controller('PresentationController', function($scope, $routeParams) {
    console.log($routeParams);
});

This does not work. I do not need ngView, but I added it if necessary. My controller is already loaded with the ng-controller directive.

+3
source share
1 answer

You need to constantly look $routeParams.idat the changes in this case: http://plnkr.co/edit/x2cPxVWPqVePDule1aOk?p=preview

$scope.$watch(function () { return $routeParams.id; }, function (newVal) {
  if (typeof newVal === 'undefined') return;
  $scope.id = newVal;
})

It is also a must have ng-viewin the template.

+3
source

All Articles