2

I want to create a details page in Angular and want to pass an entry id with the RouterLink. Is there a way to get the parameter in the url?

The URL looks like: http://localhost:8080/details?date=13-09-2016

2 Answers 2

2

Also RouteParams can be used to get the parameter. You can injected it to your component:

@Component(...)
class MyDetailsComponent {
  final RouteParams _routeParams;
  MyDetailsComponent(this._routeParams){
    var date = _routeParams.get('date');
  }
}

You can find more details here.

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

Comments

1

Implement OnActivate

  @override
  routerOnActivate(ComponentInstruction nextInstruction,
      ComponentInstruction prevInstruction) {
    String routeParamValue = nextInstruction.params['paramName'];
    String queryParamValue = nextInstruction.urlParams['paramName'];
  }

8 Comments

Where I have to put this? Do I have to put this in the class part of the component?
To the component added by the router. You need to change params to queryParams for query parameters. param is for route parameters (path: '/some/:paramName/other')
It doesn't work. It is even not called I already changed it to queryParams but it isn't even called. My Routing looks like this: @RouteConfig(const [ const Route(path: '/view', name: 'Home', component: SimpleKVComponent, useAsDefault: true), const Route(path: '/settings', name: 'Settings', component: SettingsComponent), const Route(path: '/details', name: 'Details', component: DetailsComponent) ])
And it is called by this line: <td><a [routerLink]="['/Details', { date: history['link'] }]"><i class="glyphicon glyphicon-eye-open"></i></a></td>
Did you add class DetailsComponent implements OnActivate {?
|

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.