【发布时间】:2017-08-23 08:59:49
【问题描述】:
在我们的应用程序中,我使用翻译管道并将选择的语言存储在 StorageProvider(本地存储)中
我的问题是,当我们更改子页面中的值时,离子菜单(在 app.html、app.component 上)无法翻译成所选语言。我的app.html 代码如下;
app.html
<ion-menu [content]="content">
<ion-content class="smrt-dark">
<ion-list>
<button color="dark" menuClose ion-item *ngFor="let p of pages" (click)="openPage(p)" style="height: 150%" [hidden]="!isAuthenticate(p.isAccess)">
<i class="fa fa-{{p.icon}} {{p.color}} circle-i-mn smrt-{{p.color}}" aria-hidden="true" item-start></i>
{{p.title}}
</button>
</ion-list>
</ion-content>
</ion-menu>
<ion-nav [root]="rootPage" #content swipeBackEnabled="false"></ion-nav>
app.component.ts
export class MyApp {
@ViewChild(Nav) nav: Nav;
rootPage: any = LoginPage;
pages: Array<{ title: string, component: any, icon: string, color: string, isAccess: string }>;
LANGUAGE;
constructor(...) {
console.log('main');
if ( this.db._config.LANGUAGE === null){
this.storage.get('language'). then( (data) => {
this.LANGUAGE = data;
this.translateService.use(this.db._config.LANGUAGE);
// used for an example of ngFor and navigation
this.pages = [
{title: translateService.instant('home'), component: HomePage, icon: 'home', color: '', isAccess: 'HOME_LIST'},
{title: translateService.instant('notes'), component: ListNotePage, icon: 'book', color: 'note', isAccess: 'NOTE_LIST'},
{title: translateService.instant('tasks'), component: ListTaskPage, icon: 'check', color: 'task', isAccess: 'ISSUE_LIST'}
];
});
}
this.initializeApp();
}
isAuthenticate(key: string){
return this.auth.isAuthenticate(key);
}
initializeApp()
{
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
});
}
如果有任何可用的方法来访问app.component.ts 属性,我也可以接受这个解决方案。
感谢您的解决方案。
【问题讨论】:
标签: angular ionic-framework ionic2