首页 > 解决方案 > 将布尔变量传递到路由器出口

问题描述

我有这个代码:

应用组件.ts

 public euskera: boolean;

ngOnInit(): void {

    this.euskera=false;
  }

  setEuskera(){
    this.euskera=true;
  }
  setCastellano(){
    this.euskera=false;
  }

想将 euskera 的值传递给路由器插座中的孩子:

app.component.html

  <div id="content">
    <router-outlet [euskera]="euskera">
    </router-outlet>

  </div>

home.component.ts

  public title: string
  public title_eus: string;
  @Input() euskera:boolean=false;

home.component.html

<div *ngIf="euskera">
  <h1>{{title_eus}}</h1>
</div>

<div *ngIf="!euskera">
  <h1>{{title}}</h1>
</div>

如何通过路由器插座传递变量的值以从我的所有组件中获取它并让 IF 进行匹配?

标签: angular

解决方案


您可以尝试使用角度定位

https://www.freecodecamp.org/news/how-to-implement-localization-in-angular-using-i18n-tools-a88898b1a0d0/

编辑:或调用不同的组件...


推荐阅读