html - 我们如何使用下拉菜单以角度选择不同的 message.xlf 文件?
问题描述
我需要在 Angular 中编写方法或函数,以便通过下拉菜单选择要显示的语言。但是我对下拉列表进行了编码,但我不知道如何编写下拉列表和 message.fr.xlf 文件之间的链接并在之后在屏幕上显示内容。你能帮我吗,我被困在这个问题上 3 天......?我的 app.component.ts 文件是 >
import { Component, LOCALE_ID, Inject } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
minutes = 0;
gender = 'female';
fly = true;
logo = 'https://angular.io/assets/images/logos/angular/angular.png';
heroes: string[] = ['Magneta', 'Celeritas', 'Dynama'];
public items: Array<string>;
inc(i: number) {
this.minutes = Math.min(5, Math.max(0, this.minutes + i));
}
male() { this.gender = 'male'; }
female() { this.gender = 'female'; }
other() { this.gender = 'other'; }
myFuncEnglish(lang) {
if (lang === 'EN') {
console.log('function called is english');
} else {
console.log('function called is french');
}
}
}
我的 HTML 文件是:
<h1 i18n="User welcome|An introduction header for this sample@@introductionHeader">
Hello i18n!
</h1>
<ng-container i18n>I don't output any element</ng-container>
<br />
<img [src]="logo" i18n-title title="Angular logo" />
<br>
<button (click)="inc(1)">+</button> <button (click)="inc(-1)">-</button>
<span i18n>Updated {minutes, plural, =0 {just now} =1 {one minute ago} other {{{minutes}} minutes ago}}</span>
({{minutes}})
<br><br>
<button (click)="male()">♂</button> <button (click)="female()">♀</button> <button (click)="other()">⚧</button>
<span i18n>The author is {gender, select, male {male} female {female} other {other}}</span>
<br><br>
<span i18n>Updated: {minutes, plural,
=0 {just now}
=1 {one minute ago}
other {{{minutes}} minutes ago by {gender, select, male {male} female {female} other {other}}}}
</span>
<select (ngModelChange)="myFuncEnglish($event)" [(ngModel)]="lang">
<option value="EN">English</option>
<option value="FR">France</option>
</select>
解决方案
推荐阅读
- jquery - 将标签值绑定到 TextBox 的 MaxLenght
- java - 使用 Java DOM 重新组织 XML - Hierarchy_Request_Error
- angular - 如何设计响应的打字稿模型?
- angular - 如何使用angular2中的primeng将控制台中的数据绑定到html
- java - 如何使用 Java 中的流在字符串列表中查找最大长度?
- bash - WebStorm:使用“run”运行时出现bash脚本错误,但在控制台中执行时有效
- json - SQL Server 插入带有其他外部参数的 JSON 数据
- javascript - 在 HTML 中切换图像隐藏/可见
- android-studio - 如何配置 Android Studio 以识别带有 SystemApi 注释的方法
- javascript - 物化日期选择器仅在单击完成按钮时更新