Angularjs 如何对枚举使用ng if条件?(angular2/打字稿)

Angularjs 如何对枚举使用ng if条件?(angular2/打字稿),angularjs,typescript,angular,enums,Angularjs,Typescript,Angular,Enums,我有一个视图,在该视图中有3个按钮: showListOne() showListTwo() showListThree() 单击每个按钮时,我希望在同一视图中显示不同的列表,但不同时显示(一次仅显示一个列表,如选项卡行为) 所以我想用Enum来做这件事,就是这样: 导出枚举CurrentListView{人、车、地点} @Component({ selector: 'my-app', styles: [require('./my-app.css')], directives:

我有一个视图,在该视图中有3个按钮:

showListOne()

showListTwo()

showListThree()
单击每个按钮时,我希望在同一视图中显示不同的列表,但不同时显示(一次仅显示一个列表,如选项卡行为)

所以我想用Enum来做这件事,就是这样:

导出枚举CurrentListView{人、车、地点}

@Component({
  selector: 'my-app',
  styles: [require('./my-app.css')],
  directives: [DND_DIRECTIVES],
  providers: [DND_PROVIDERS],
  template: require('./my-app.component.html')
})

  @Injectable()
  export class AppCmp implements OnInit {

    listOfPeople: Person[];
    listOfCars: Car[];
    listOfPlaces: Place[];

    currentListView: CurrentListView;

    constructor(private _MyService: MyService) {
    };

    public showListOfPeopleData(): void {
      this.currentListView = CurrentListView.People;
    }

    public showListOfCarsData(): void {
      this.currentListView = CurrentListView.Cars;
    }

    public showListOfPlacesData(): void {
      this.currentListView = CurrentListView.Places;
    }

    ngOnInit() {
      this._MyService.getListOfPeopleData().subscribe(res => {
        this.listOfPeople = res;
      });

      this._MyService.getListOfCarsData().subscribe(res => {
        this.listOfCars = res;
      });

      this._MyService.getListOfPlacesData().subscribe(res => {
        this.listOfPlaces = res;
      });
    }
  }
现在,如何使用ng if询问
currentListView
的状态?这是我的观点(如果有我尝试过的,并且它不起作用,则为ng):


ID:{{person.ID}年龄:{{person.Age}
ID:{car.ID}Color:{{car.Color}
城市:{place.City}容量:{{place.Capacity}
我的打字脚本或html能更高效吗?我很想看到一个建议,一个更通用的方式来做到这一点,没有重复


谢谢你

我认为您无法比较阵列(更不用说它的性能很差), 我建议您可以将“要显示的列表”存储在某个字符串变量中 大概是这样的:

    currentListView:string = 'Bikes';

像这样

我建议用不同的方式来做。将每个视图放入组件中,然后设置到每个视图的管线。您的按钮将成为加载相应组件的路由器链接。
    currentListView:string = 'Bikes';