【问题标题】:ngx-translate not working in ng-bootstrap modalngx-translate 在 ng-bootstrap 模式下不起作用
【发布时间】:2017-08-30 09:43:36
【问题描述】:

ngx-translatetranslate 管道在 ng-bootstrapmodal 内不起作用。

<div class="modal-header">
  <h3 class="modal-title">
    {{ 'MODAL.TITLE' | translate }}
  </h3>
</div>

<div class="modal-body">
</div>

<div class="modal-footer">
  <button class="btn btn-primary" type="button" (click)="activeModal.close('Close click')">
    <span class="fa fa-remove"></span> {{ 'BUTTON.CLOSE' | translate }}
  </button>
</div>

【问题讨论】:

标签: angular ng-bootstrap ngx-translate


【解决方案1】:

ngx-translateReadme 上写着:

注意:如果您仍在使用 Angular

那么有什么区别呢?

在 Angular >= 4.3.x 中,您现在需要提供 HttpClient,而不是提供 HttpTranslateModule

app.module.ts :

import {HttpClient, HttpClientModule} from "@angular/common/http"; //<-- before import {HttpModule, Http} from "@angular/http";
...
export function HttpLoaderFactory(httpClient: HttpClient) { //<-- before Http
    return new TranslateHttpLoader(httpClient, "i18n/", ".json");
}

@NgModule({
    imports: [
        ...
        HttpClientModule, //<-- before HttpModule
        TranslateModule.forRoot({
          loader: {
            provide: TranslateLoader,
            useFactory: HttpLoaderFactory,
            deps: [HttpClient] //<-- before Http
          }
        })
    ],
    ...
})

我分叉并修复了 Angular Demo (4.3.6):https://plnkr.co/edit/1VZdWdQvat3lxaXYVZs3?p=preview

【讨论】:

  • ngx-translateng-bootstrap 的模态之外完美工作。感谢您是否可以创建一个集成了这两者的 Plunker。 ng-bootstrap.github.io/#/components/modal/examples
  • @RogerNg 在这里,我只是将代码移到模态中,一切似乎都在工作:plnkr.co/edit/z5bB63YihlRPYmJ3Giqh?p=preview 是嵌套模块中的模态吗?
  • 我将第二个示例“组件作为内容”用于 ng-bootstrap 模态。
  • 我有一个主模块和一个应用模块。主模块和应用模块之间没有关系。该组件位于主模块下。 TranslateModule.forRoot() 被导入到应用模块中。
  • @RogerNg 我制作了一个单独的组件modal.component.ts。在app.component.ts 中,它调用&lt;modal-component&gt; 并将其内容传递给模态。那是你要找的吗?在这里工作:plnkr.co/edit/SCgp90BmSzXbRAML37fj?p=preview
猜你喜欢
  • 1970-01-01
  • 2018-08-06
  • 1970-01-01
  • 2018-04-01
  • 2018-01-14
  • 1970-01-01
  • 2020-09-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多