how to get the alias from the angular-new-router?

510 views Asked by At

in angular-new-router, user can specify an alias for a component:

MyController.$routeConfig = [
  { path: '/', component: 'user', as: 'myUser' }
];

and we can activate it :

<a ng-link="myUser">link to user component</a>
<a ng-link="user">link to user component</a>

Is there a way to know which link user clicks by looking at alias in the controller? thanks.

1

There are 1 answers

1
Andrew Arnautov On

here is latest example and you need to use angular_1_router.js built from angular2 project instead of installing package of angular-new-router (until it is updated) in a new version they use angular 1.5 and fixed it so you can use components() and child routes etc.

http://plnkr.co/edit/N3YP3dKMuljpZ6mWsVBT?p=preview

app.js

angular.module('app', ['ngComponentRouter', 'dialog', 'heroes', 'crisis-center'])

.config(function($locationProvider) {
  $locationProvider.html5Mode(true);
})

.run(function($router) {
  $router.config([
    { path: '/...', name: 'App', component: 'app', useAsDefault: true }
  ]);
  $router.navigate(['App']);
})

.component('app', {
  template:
    '<nav>\n' +
    '  <a ng-link="[\'CrisisCenter\']">Crisis Center</a>\n' +
    '  <a ng-link="[\'Heroes\']">Heroes</a>\n' +
    '</nav>\n' +
    '<ng-outlet></ng-outlet>\n',
  $routeConfig: [
    {path: '/crisis-center/...', name: 'CrisisCenter', component: 'crisisCenter', useAsDefault: true},
    {path: '/heroes/...', name: 'Heroes', component: 'heroes'},
    {path: '/disaster', name: 'Asteroid', redirectTo: ['CrisisCenter', 'CrisisDetail', {id:3}]}
  ]
});