【发布时间】:2020-04-07 17:12:09
【问题描述】:
我需要路由到另一个组件,正如您在路径中看到的那样,但我需要将变量 this.a 一起传递。我该如何做才能将此变量的值用于其他组件?
组件.ts
import {Component, OnDestroy,OnInit, Input} from '@angular/core';
import { ChangeDetectorRef } from '@angular/core';
import { Router } from '@angular/router';
import { analyzeAndValidateNgModules } from '@angular/compiler';
import { ParkingService } from '../../../services/parking.service';
import { Injectable } from '@angular/core';
import { Subject, BehaviorSubject } from 'rxjs';
@Component({
selector: 'ngx-homepage',
styleUrls: ['./homepage.component.scss'],
templateUrl: './homepage.component.html',
providers: [ParkingService]
})
@Injectable()
export class HomepageComponent implements OnInit {
a:string;
constructor (public parkingService: ParkingService, public root:Router) {
}
ngOnInit(){
}
pass(passa)
{
this.a= passa.value;
window.alert(this.a);
this.parkingService.setUserToken(this.a);
this.root.navigate(['/pages/iot-dashboard']);
}
}
【问题讨论】:
标签: angular