【发布时间】:2018-07-08 00:26:23
【问题描述】:
根据本教程http://codingscripts.com/ionic-3-multi-language-app/,我有翻译服务,它工作正常。但在本教程中,您将添加按钮以更改 home.html 页面上的语言。
我希望我的按钮位于我的应用程序的侧边菜单中,所以这将是 app.html。 我将按钮添加到我的 app.html 中,例如:
<button (click)="changeLanguage('de')">
Translate to German
</button>
<button (click)="changeLanguage('fr')">
Translate to French
</button>
我的 app.component.ts 看起来像这样:
import ......
import { TranslateService } from '@ngx-translate/core';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
...;
constructor(..., public translate: TranslateService) {
....
});
}
changeLanguage(language) {
this.translate.use(language);
}
}
当我启动我的应用并单击按钮时,我收到此错误:TypeError: _co.changeLanguage is not a function
我已经用谷歌搜索了这个错误,但找不到任何解决这个问题的方法。
【问题讨论】:
-
你能分享整个errorStack吗?还有你的 app.component.ts?
-
只需停止 ionic serve 并重新运行。在 Ionic 中,如果您添加了任何不会反映在 live-reload 中的附加功能。
-
@yousuf 就是这样。谢谢。
标签: angular ionic3 typeerror ngx-translate