Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {Injectable} from '@angular/core';
- import * as Rx from 'rxjs';
- @Injectable()
- export class TransmitRouteService {
- data = new Rx.Subject();
- constructor() {
- /* I tried this just to see if it would sync I/O. */
- /* It did not. */
- // this.data.next('aaa');
- }
- insertData(data){
- this.data.next(data);
- }
- }
- @NgModule({
- declarations: [
- AppComponent,
- Menu1,
- Menu2,
- Menu3,
- Menu4,
- Menu5,
- Menu6,
- ],
- imports: [
- BrowserAnimationsModule,
- BrowserModule,
- AppRouting
- ],
- exports: [],
- providers: [TransmitRouteService],
- bootstrap: [AppComponent]
- })
- export class AppModule {
- }
- import {Component, OnInit} from '@angular/core';
- import {Router} from '@angular/router';
- import { slideLeft, slideRight } from '../../../../assets/animations/router.animations';
- import {TransmitRouteService} from "../../../../assets/services/transmit.route.service";
- @Component({
- selector: 'app-routing',
- templateUrl: './routing.component.html',
- styleUrls: ['./routing.component.scss'],
- animations: [slideLeft, slideRight],
- host: { '[@slideLeft, slideRight]': '' }
- })
- export class RoutingComponent implements OnInit {
- router:any;
- constructor(private _router: Router, private _transmitRouteService: TransmitRouteService) {
- this.router = _router;
- }
- ngOnInit() {
- }
- getState(outlet) {
- this._transmitRouteService.insertData(this.router.url);
- return outlet.activatedRouteData.state;
- }
- }
- import { Component, OnInit } from '@angular/core';
- import {TransmitRouteService} from '../../../assets/services/transmit.route.service';
- @Component({
- selector: 'app-top-bar',
- templateUrl: './top-bar.component.html',
- styleUrls: ['./top-bar.component.scss'],
- })
- export class TopBarComponent implements OnInit {
- route: string = '';
- constructor(private _transmitRouteService: TransmitRouteService) { }
- ngOnInit() {
- this._transmitRouteService.data.subscribe((value) => {
- this.route = value.toString();
- }, (error) => {
- console.log(error);
- }, () => {
- console.log('done !');
- });
- }
- }
- Input: Output:
- Hello
- World Hello
- I World
- Am I
- Tatsu Am
Add Comment
Please, Sign In to add comment