Send text by Routes (Children)

Asked

Viewed 46 times

1

I send the title like this:

  const routes: Routes = [
  Route.withShell([
    {
      path: 'ex',
      component: exemple,
      children: [
        {
          path: '',
          component: exComponent,
          data: {
            title: extract('ex.PAGE_TITLE')
          },...

Is there any way to send a text to put in my breadcrumb tbm?

No header ts i do:

  import { Title } from '@angular/platform-browser';
    ....
      constructor(
    private titleService: Title

  ) { }

  ngOnInit() {
  }

  get title(): string {
    return this.titleService.getTitle();
  }

and in header.html:

 <ol class="breadcrumb">
        <li class="breadcrumb-item">{{title}}</li>
        <li class="breadcrumb-item" > <a (click)="add()">{{text}}</a></li>
      </ol>

ai would like to send a text to it too, besides the title, to use globally in the project

  • You could send another parameter besides the title inside data and read in the same way as title. Wouldn’t that be your question?

  • @Marcelovismari my doubt is how to get hold of this other data

1 answer

0

Add information exactly like title:

// (...)
path: '/',
component: MyPageComponent,
data: {
    title: 'Meu titulo',
    outraInfo: 'teste'
}
// (...)

Example of how to read title and outraInfo:

// (...)
constructor(private router: Router,
            private activatedRoute: ActivatedRoute,
            private titleService: Title) {
}

ngOnInit() {
    this.router.events
        .pipe(filter(event => event instanceof NavigationEnd))
        .pipe(map(() => this.activatedRoute))
        .pipe(map(route => {
            while (route.firstChild) {
                route = route.firstChild;
            }

            return route;
        }))
        .pipe(switchMap(route => route.data))
        .subscribe(event => {
            console.log(event);
            this.titleService.setTitle(event.title);
            // Resultado no console: {title: "Meu titulo", outraInfo: "teste"}
        });
}
// (...)
  • worked, but when I send the otherInfo has to go the data that is in en.json, which I put like this: ''''DOCS.ADD_TAX_COUPON.TITLE' , but la ta showing exactly this string, and not this data. And just when it starts it doesn’t show, it only shows if I navigate between the screens and go back to it

  • @Maria has already tried to use the translatePipe right in the template? I imagine you’re using ngx-translate, so leave on the template something like {{title | translate}} and in the AppComponent feed the variable title as the example above. The same rule for the outraInfo. Would this be?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.