Guest User

Untitled

a guest
Feb 13th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. import {Injectable} from '@angular/core';
  2. import * as Rx from 'rxjs';
  3.  
  4. @Injectable()
  5. export class TransmitRouteService {
  6.  
  7. data = new Rx.Subject();
  8.  
  9. constructor() {
  10. /* I tried this just to see if it would sync I/O. */
  11. /* It did not. */
  12. // this.data.next('aaa');
  13. }
  14.  
  15.  
  16. insertData(data){
  17. this.data.next(data);
  18. }
  19. }
  20.  
  21. @NgModule({
  22. declarations: [
  23. AppComponent,
  24. Menu1,
  25. Menu2,
  26. Menu3,
  27. Menu4,
  28. Menu5,
  29. Menu6,
  30. ],
  31. imports: [
  32. BrowserAnimationsModule,
  33. BrowserModule,
  34. AppRouting
  35. ],
  36. exports: [],
  37. providers: [TransmitRouteService],
  38. bootstrap: [AppComponent]
  39. })
  40. export class AppModule {
  41. }
  42.  
  43. import {Component, OnInit} from '@angular/core';
  44. import {Router} from '@angular/router';
  45. import { slideLeft, slideRight } from '../../../../assets/animations/router.animations';
  46. import {TransmitRouteService} from "../../../../assets/services/transmit.route.service";
  47.  
  48.  
  49. @Component({
  50. selector: 'app-routing',
  51. templateUrl: './routing.component.html',
  52. styleUrls: ['./routing.component.scss'],
  53. animations: [slideLeft, slideRight],
  54. host: { '[@slideLeft, slideRight]': '' }
  55. })
  56. export class RoutingComponent implements OnInit {
  57.  
  58. router:any;
  59.  
  60. constructor(private _router: Router, private _transmitRouteService: TransmitRouteService) {
  61. this.router = _router;
  62. }
  63.  
  64. ngOnInit() {
  65. }
  66.  
  67. getState(outlet) {
  68. this._transmitRouteService.insertData(this.router.url);
  69. return outlet.activatedRouteData.state;
  70. }
  71.  
  72. }
  73.  
  74. import { Component, OnInit } from '@angular/core';
  75. import {TransmitRouteService} from '../../../assets/services/transmit.route.service';
  76.  
  77. @Component({
  78. selector: 'app-top-bar',
  79. templateUrl: './top-bar.component.html',
  80. styleUrls: ['./top-bar.component.scss'],
  81. })
  82. export class TopBarComponent implements OnInit {
  83.  
  84. route: string = '';
  85.  
  86. constructor(private _transmitRouteService: TransmitRouteService) { }
  87.  
  88. ngOnInit() {
  89. this._transmitRouteService.data.subscribe((value) => {
  90. this.route = value.toString();
  91. }, (error) => {
  92. console.log(error);
  93. }, () => {
  94. console.log('done !');
  95. });
  96. }
  97.  
  98. }
  99.  
  100. Input: Output:
  101. Hello
  102. World Hello
  103. I World
  104. Am I
  105. Tatsu Am
Add Comment
Please, Sign In to add comment