Share data between components using a service in Angular2

camaron is right. Your mistake is that you declare UtilityService twice: Once in the providers of SearchComponent. Once in the providers of TransferComponent. You should declare the service ONLY ONCE to make sure both components get the same instance. For this you can choose between either of these options: Declare the service in the providers … Read more

Autoscroll in Angular 2

update Currently there is no automatic way. See also Angular 2 typescript error when using subscribe function on new router (rc 1) See also https://github.com/angular/angular/issues/6595#issuecomment-244232725 class MyAppComponent { constructor(router: Router) { router.events.subscribe(s => { if (s instanceof NavigationEnd) { const tree = router.parseUrl(router.url); if (tree.fragment) { // you can use DomAdapter const element = document.querySelector(“#” … Read more

Custom encoding for urls using Angular 2 Router (using a + sign in place of a space)

I was able to find a solution to my problem. You can make own custom url serializer by implementing the UrlSerializer class. Custom Url Serializer Create a custom url serializer like this: @Injectable() export class CustomUrlSerializer implements UrlSerializer { constructor(private defaultUrlSerializer: DefaultUrlSerializer){} parse(url: string): UrlTree { // Custom code here } serialize(tree: UrlTree): string { … Read more

Angular2 Routing – keeping state of component when route changes [duplicate]

update 2 That’s now fixed (Angular 2.3) for the new router by https://github.com/angular/angular/pull/13124 which allows to provide a custom reuse strategy. For an example see also https://www.softwarearchitekt.at/post/2016/12/02/sticky-routes-in-angular-2-3-with-routereusestrategy.aspx Angular docs https://angular.io/api/router/RouteReuseStrategy update 2 This answer is only for a long ago discontinued router version. See https://angular.io/docs/ts/latest/guide/router.html#!#guards for how to do it in the current router. original … Read more

New Angular2 router configuration

In the new router (>= RC.3) https://angular.io/docs/ts/latest/api/router/index/Router-class.html resetConfig can be used router.resetConfig([ { path: ‘team/:id’, component: TeamCmp, children: [ { path: ‘simple’, component: SimpleCmp }, { path: ‘user/:name’, component: UserCmp } ] } ]); You might need to provide some dummy router configuration to not get errors on application startup. https://github.com/angular/angular/issues/11437#issuecomment-245995186 provides an RC.6 Plunker