1

This is my component:

@Component({
  selector: 'ngx-pages',
  styleUrls: ['pages.component.scss'],
  template: `
    <ngx-one-column-layout>
      <nb-menu [items]="menu"></nb-menu>
      <router-outlet></router-outlet>
    </ngx-one-column-layout>
  `,
})
export class PagesComponent {
  constructor(private translate: TranslateService) {
    console.log(this.translate.instant('adminPanel'));
  }

  menu = MENU_ITEMS;

  ngOnInit(): void {
    MENU_ITEMS[0]["title"]= this.translate.instant('adminPanel');
    this.menu = MENU_ITEMS;
  }
}

Everything works fine, but changing the menu variable when I overwrite it does not change in the html until I exit the page and re-enter, indicating that it was changed late and does not support the change dynamically. I tried to assign an EventEmitter to the nb menu, but can't, since I can't enter the nb-menu to change it from the inside because it's a null-shaped tag (a frame I downloaded it)

1 Answer 1

1

Try to assign value as

  ngOnInit(): void {
    MENU_ITEMS[0]["title"]= this.translate.instant('adminPanel');
    this.menu = JSON.parse(JSON.stringify(MENU_ITEMS));
  }

For array with objects, angular wont be able to detect changes. So, you need to provide new array as JSON.parse(JSON.stringify(MENU_ITEMS))

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.