Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

angular8 PrimeNg tabview

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() {
  }
}
Comment

angular8 PrimeNg tabview

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() {
  }
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: alternative for .include in typescript 
Typescript :: - laravel/ui[v3.2.0, ..., 3.x-dev] require illuminate/console ^8.0 - found illuminate/console[v8.0.0, ..., 8.x-dev] but these were not loaded, likely because it conflicts with another require. 
Typescript :: setup react with serverless stack 
Typescript :: e.target.value typescript 
Typescript :: nestjs called once method 
Typescript :: isolate digits in large number cpp 
Typescript :: how to find geopoints radius in mongoose 
Typescript :: The Apple I had a built-in video terminal, sockets for __________ kilobytes of onboard random access memory (RAM), a keyboard, and a cassette board meant to work with regular cassette recorders. 
Typescript :: how to find nuber of tweets per day using python 
Typescript :: sprockets cannot load such file sass 
Typescript :: call appply bind 
Typescript :: Jane and the Frost Giants "c++" 
Typescript :: lofi hip hop beats cool 
Typescript :: consisting either of digits only or Latin letters 
Typescript :: python Implement the function is_even(number) which gets an integer as input parameter and checks, if this input is even or not 
Typescript :: loading assets in ionic react 
Typescript :: translate a vector 
Typescript :: centos remote desktop clients vs remote management for linux 
Typescript :: rac bar charts plotly 
Typescript :: multi inputs in one line c++ 
Typescript :: get_refreshed_fragments too long to load 
Typescript :: typescript directory structure 
Typescript :: writhing requests to text file 
Typescript :: c# check type implements generic interface 
Typescript :: combine 2 lists to dataframe python 
Typescript :: prolog check if element in different lists are same 
Typescript :: meta tag utf-8 means kya hota hai 
Cpp :: conda list envs 
Cpp :: flutter convert datetime in day of month 
Cpp :: npm install error 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =