angular 选中切换面板

此方法采用的是没有路由的方式;

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代码:

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
    )
  }

 

 

posted @ 2017-08-16 09:51  前端进阶中  阅读(212)  评论(0编辑  收藏  举报