angular8 PrimeNg tabview

The solution for “angular8 PrimeNg tabview” can be found here. The following code will assist you in solving the problem.

export class AppTabViewComponent implements AfterViewInit, OnInit {

closable: boolean = true

model: any[];

activeIndex = 0

@Input()
tabs: MenuItem[] = [];

menuSourceSubscription: Subscription;

constructor(public appMain: AppMainComponent, public menuService: MenuService,
public changeDetectorRef: ChangeDetectorRef, public zone: NgZone,
private sanitizer: DomSanitizer) {

this.menuSourceSubscription = this.menuService.menuSource$.subscribe(key => {
this.openNewTab(key)
});
}

ngAfterViewInit(): void {
this.closable = true
}

handleClose(e) {
console.log(e.index)
this.tabs.splice(e.index-1,1)
if (this.tabs.length == 0){
this.activeIndex = 0
}else{
if(this.activeIndex === e.index){
this.activeIndex = e.index – 1
}
}
e.close();
}

openNewTab(item): void {
if (this.tabs.indexOf(item) > -1) {
setTimeout(() => {
this.activeIndex = this.tabs.indexOf(item) + 1;
})
} else {
item.routerLink = this.sanitizer.bypassSecurityTrustResourceUrl(window.location.protocol + ‘//’ + window.location.host + ‘/#’ + item.routerLink[0])
console.log(item)
this.tabs.push(item);
setTimeout(() => {
this.activeIndex = this.tabs.length;
})
}
}

// onContextMenu(event, id) {
// console.log(event.originalEvent.target)
// }

ngOnInit() {
}
}

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in