Git Product home page Git Product logo

Comments (4)

logicappsource avatar logicappsource commented on June 13, 2024 6

I find it incredibly hard to use it in Angular 17 without the module structure.

  {
    path: `${environment.seo.service}`,
    loadComponent: () =>
      import('../pages/seo/seo.component').then((c) => c.SeoComponent),
    providers: [
      importProvidersFrom([
        TranslateModule.forChild({
          loader: {
            provide: TranslateLoader,
            useFactory: () => {
              return new TranslateJsonLoader();
            },
          },
        }),
      ]),
    ],
  },

Is this corrrect understood this is the new way we should implement pr lazyloading basis of a component?.

I keep getting the following error: 
ERROR Error [NullInjectorError]: R3InjectorError(Standalone[_SeoComponent])[_TranslatePipe -> _TranslatePipe -> _TranslatePipe -> _TranslatePipe]: 
  NullInjectorError: No provider for _TranslatePipe!
    at NullInjector.get (/Users/patricksahlgren/Desktop/Handyhand/handyhand-seo/node_modules/@angular/core/fesm2022/core.mjs:5605:27)
    at R3Injector.get (/Users/patricksahlgren/Desktop/Handyhand/handyhand-seo/node_modules/@angular/core/fesm2022/core.mjs:6048:33)
    at R3Injector.get (/Users/patricksahlgren/Desktop/Handyhand/handyhand-seo/node_modules/@angular/core/fesm2022/core.mjs:6048:33)
    at R3Injector.get (/Users/patricksahlgren/Desktop/Handyhand/handyhand-seo/node_modules/@angular/core/fesm2022/core.mjs:6048:33)
    at R3Injector.get (/Users/patricksahlgren/Desktop/Handyhand/handyhand-seo/node_modules/@angular/core/fesm2022/core.mjs:6048:33)
    at ChainedInjector.get (/Users/patricksahlgren/Desktop/Handyhand/handyhand-seo/node_modules/@angular/core/fesm2022/core.mjs:15426:36)
    at lookupTokenUsingModuleInjector (/Users/patricksahlgren/Desktop/Handyhand/handyhand-seo/node_modules/@angular/core/fesm2022/core.mjs:4116:39)
    at getOrCreateInjectable (/Users/patricksahlgren/Desktop/Handyhand/handyhand-seo/node_modules/@angular/core/fesm2022/core.mjs:4164:12)
    at Module.ɵɵdirectiveInject (/Users/patricksahlgren/Desktop/Handyhand/handyhand-seo/node_modules/@angular/core/fesm2022/core.mjs:11987:19)
    at NodeInjectorFactory.SeoComponent_Factory (/Users/patricksahlgren/Desktop/Handyhand/handyhand-seo/src/app/pages/seo/seo.component.ts:127:24) {
  ngTempTokenPath: null,
  ngTokenPath: [
    '_TranslatePipe',
    '_TranslatePipe',
    '_TranslatePipe',
    '_TranslatePipe'
  ]
}

TranslateJsonLoader:

import { TranslateLoader } from '@ngx-translate/core';
import { of } from 'rxjs';

import * as dk from 'assets/i18n/dk.json';
import * as en from 'assets/i18n/en.json';
import { environment } from '../environments/environment.dk';

export class TranslateJsonLoader implements TranslateLoader {
  constructor() {}

  public getTranslation() {
    switch (environment.language) {
      case 'dk':
        {
          return of(dk);
        }
        break;
      case 'en':
        {
          return of(en);
        }
        break;
      default:
        {
          return of(dk);
        }
        break;
    }
  }
}

Please help, @johnsonlin , @mtabaj :)

Running Angular v. 17. latest version of ngx-translate.

from core.

johnsonlin avatar johnsonlin commented on June 13, 2024

You can put it in your app routes like so:

export const routes: Routes = [
  ...
  {
    path: 'example',
    loadComponent: () => import(...).then(mod => mod.ExampleComponent),
    providers: [
      importProvidersFrom([
        TranslateModule.forChild(...)
      ])
    ]
  }
  ...
]

from core.

lppedd avatar lppedd commented on June 13, 2024

I'm wondering if for small projects it makes sense to just stick with modules for now.

from core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.