angular 選中切換面板

此方法採用的是沒有路由的方式;html

html5 代碼:html5

<div [hidden]="flag">
    <li class="music-list-datails">熱門</li>
    <li class="music-list-datails" *ngFor="let c of category" [class.selected]="c === selectedc" (click)="onSelect(c)">{{c.category_name}}</li>
</div>
 
<div *ngIf="selectedc">
    <li class=" swiper-slide music-list-datails " (click)="goback()">返回上一級</li>
    <li class="swiper-slide music-list-datails " *ngFor="let audio of selectedc ">{{audio.tag_name}}</li>
</div>
ts代碼:

ts代碼:ide

errorMessage: string;
category: Category[];
selectedc: Tag[];
flag;
constructor(private fmService: FMService, private location: Location) { }
 ngOnInit() {
  this.getCategoryList();
 }
getCategoryList() {
    this.fmService.getCategoryList().then(
      category => {
       this.category = category;
     },
     error => this.errorMessage = <any>error
   )
  }
 
  onSelect(c): void {
   this.fmService.getAudiobook(c.id).then(
     tag => {
        this.selectedc = tag;
        this.flag = true;
     },
      error => this.errorMessage = <any>error
    )
  }

 
相關文章
相關標籤/搜索