angularscopetransloco

Angular - Transloco read in 2 scopes


I have a problem with transloco. I would like to read in 2 scopes in the same html. I manage to provide scope in my module and to read in 2 scopes declaring 2 read attributes.

The question is :

Can I define 2 scope in the same read ?

Example :

<div class="fr-container" *transloco="let t; read: 'scope1', 'scope2' ">

this don't seems working. What is the better way else ?

Thanks for any help !


Solution

  • The read does not support multiple inputs, you can wrap multiple ng-container with different varaible names, so that the scope is maintained!

    source code

    <ng-container *transloco="let t">
      <ng-container *transloco="let v; read: 'nested'">
        <h1>from T Scope</h1>
        <p data-cy="todos-page-scope">{{ t('todos.title') }}</p>
        <p data-cy="global">{{ t('home') }}</p>
        <h1>from V Scope</h1>
        <h5>{{ v('title') }}</h5>
        <p>{{ v('desc') }}</p>
      </ng-container>
    </ng-container>
    

    stackblitz