Phil
Phil

Reputation: 50386

How to get route parameters in the AngularDart component in my view?

In AngularDart, how can I get the route parameters from within my component which is in a view?

As far as I have managed to get is that in my router, I believe I should add parameters as such:

'class': ngRoute(
    path: '/class/:year/:month/:day',
    view: 'views/class.html'
),

Then how can I get the year month and day in my component? its a @Component annotated class.

Upvotes: 3

Views: 1112

Answers (2)

tharindu_DG
tharindu_DG

Reputation: 9261

I think the current answer is obsolete.

import 'package:angular/angular.dart';
import 'package:angular_router/angular_router.dart';

@Component(
...
directives: [
    ...
    routerDirectives,
  ],
)
class MyComponent {
  final RouterState _route;


  MyComponent(this._route);

  final year = this.route.queryParameters['year'];
  ...
}

Hope this helps

Upvotes: 0

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657248

this should work

@Component(...)
class MyComponent {
  RouteProvider _routeProvider;

  MyComponent(this._routeProvider);

  var year = _routeProvider.parameters['year'];
  ...
}

You let inject the RouteProvider and access the parameters map.

Upvotes: 4

Related Questions