Pass invisible or hidden parameters using routerLink Angular

后端 未结 7 497
清酒与你
清酒与你 2020-12-03 10:48

I have router link like below:

I want t

7条回答
  •  心在旅途
    2020-12-03 11:02

    I'm not sure, if there is a way to do it, because the data need to be presented in the URL string.

    My suggestion is using global service which be store needed data. For example:

    //some dataService, which store your needed data.
    @Injectable()
    export class DataService {
    
       _showTour: string;
    
       set showTour(value: string) {
          this._showTour = value;
       }
    
       get showTour(): string {
           return this._showTour;
       }
    
       constructor() {}
    
    }
    

    and use it in your navigation component in this way:

    //your navigation component
    @Component({
        selector: 'my-app',
        template: `
           

    You will may use the same service in your Dashboard Component, and get needed value, f.e. in this way:

    //your dashboard component
    @Component({
        selector: 'my-dashboard',
        template: `
           

    {{ showTour }}

    ` }) export class DashboardComponent implements OnInit { showTour: string; constructor(private dataService: DataService) { } ngOnInit() { this.showTour = this.dataService.showTour; } }

提交回复
热议问题