Я создал компонент cookie.component
в папке modal/
с component.module
, который содержит все необходимое, чтобы модуль работал с переводом.
cookie.component.module
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { IonicModule } from '@ionic/angular';
import { TranslateModule } from '@ngx-translate/core';
import { FaIconLibrary, FontAwesomeModule } from '@fortawesome/angular-fontawesome';
@NgModule({
imports: [
CommonModule,
IonicModule,
TranslateModule.forChild(),
FontAwesomeModule,
],
declarations: [],
exports: []
})
export class CookieModule {
constructor(
private library: FaIconLibrary
) {
}
}
Я импортирую этот компонент в guard/cookie.guard
, который я вызвал в app-routing.module
guard/cookie.guard
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';
import { ModalController, Platform } from '@ionic/angular';
import { CookieComponent } from '../modal/cookie/cookie.component';
@Injectable({
providedIn: 'root'
})
export class CookiesGuard implements CanActivate {
constructor(
private modalController: ModalController,
private platform: Platform
) {}
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
return new Promise(async resolve => {
if (this.platform.url().includes("http") && localStorage.getItem("useAnalytics") == null) {
this.modalController.create({
component: CookieComponent,
cssClass: "cookie-modal",
backdropDismiss: false
}).then(m => {
m.present();
}).catch(err => console.error(err));
} else resolve(true);
});
}
}
а вот и app-routing.module
...
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { CookiesGuard } from './guard/cookie.guard';
const routes: Routes = [
{
path: 'home',
loadChildren: () => import('./home/home.module').then(m => m.HomePageModule),
canActivate: [CookiesGuard, LaunchGuard, ProgramChoseGuard]
},
...
];
@NgModule({
imports: [
CommonModule,
TranslateModule.forChild(),
RouterModule.forRoot(routes, {
preloadingStrategy: PreloadAllModules,
useHash: true
})
],
exports: [RouterModule]
})
export class AppRoutingModule { }
Я получаю The pipe 'translation' could not be found
, хотя в модальном cookie.component
есть необходимые импортированные ...
Есть идеи, как сделать перевод в этом конкретном случае?
Для меня цель состоит в том, чтобы у модального окна была защита с переводом, обратите внимание, что если я заменю в cookie.component.html
{{ELEMENT.el | translate}} обычным непереведенным текстом работает хорошо. И перевод работает на всех остальных страницах.