我是 Ionic/Angular 的新手,因此寻求您的帮助。到目前为止,我设法使翻译和 ngFor 在我的脚本中正常工作,但我想将它混合在我的应用程序的侧面菜单中,以便它自动翻译。
这是我在app.html 中正常工作的菜单:它列出了 app.components.ts 中的所有页面
<ion-list>
<button ion-item *ngFor="let p of pages" (click)="openPage(p)">
{{p.title}}
</button>
</ion-list>
这是我想要做的:(当我使用诸如“menu_title_1”之类的字符串时,翻译功能可以正常工作)
<ion-list>
<button ion-item *ngFor="let p of pages" (click)="openPage(p)">
{{ {{p.title}} | translate }}
</button>
</ion-list>
这是我的app.components.ts:
import { Platform, MenuController, NavController, Nav } from 'ionic-angular';
import { HomePage } from '../pages/home/home';
import { SingleTechniquePage } from '../pages/single-technique/single-technique';
import { AboutPage } from '../pages/about/about';
import { HelloIonicPage } from '../pages/hello-ionic/hello-ionic';
import { ListPage } from '../pages/list/list';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { TranslateService, TranslateModule } from '@ngx-translate/core';
(...)
this.pages = [
{ title: 'menu_singletechnique', component: SingleTechniquePage },
{ title: 'menu_helloionic', component: HelloIonicPage },
{ title: 'menu_firstlist', component: ListPage },
{ title: 'menu_about', component: AboutPage }
];
}
(...)
openPage(page) {
// close the menu when clicking a link from the menu
this.menu.close();
// navigate to the new page if it is not the current page
this.nav.setRoot(page.component);
}
再一次,一切正常,直到我尝试翻译循环内容。
非常感谢您提前!