0

我正在尝试通过组件进行翻译,因为我打算在 sweetAlert 弹出窗口中使用翻译。我得到“无法读取未定义的属性'即时'”。我想知道我错在哪里。

注意:我正在使用延迟加载模块

应用模块

imports: [
    ..., // for short
    TranslateModule.forRoot({
      loader: {
        provide: TranslateLoader,
        useFactory: HttpLoaderFactory,
        deps: [HttpClient]
      },
    })
  ],

我尝试使用 TranslateService 的服务

@Injectable({
  providedIn: "root"
})
export class UtilsService {
constructor(
    private alertMsg: ToastrService,
    private http: HttpClient,
    private router: Router,
    private storage: StorageService,
    private translate: TranslateService
  ) {

  }
}


showAlertRequestError(err: HttpErrorResponse) {
    debugger
    let erroMsgTranslated: string;
    switch (err.status) {
      case 500:
      case 404:
        erroMsgTranslated = this.translate.instant('STATUSCODEMESSAGES.CLIENTERRORS.404')
        Toast.fire(erroMsgTranslated, ` Message: ${err.message}. Status: ${err.status}`, 'error');
        break;
      case 400: 
        Toast.fire('', ` Message: ${err.error.error}. Status: ${err.status}`, 'info');
        break;
      case 408:
        erroMsgTranslated = this.translate.instant('STATUSCODEMESSAGES.CLIENTERRORS.408')
        Toast.fire(erroMsgTranslated, ` Message: ${err.error.error}. Status: ${err.status}`, 'warning');
        break;
      default:
        Toast.fire(`${err.message},`, `Stats: ${err.status}`, 'warning')
    }
  }
4

0 回答 0