在Angular 2中使用* ngIf控制多于3个div

时间:2016-12-22 06:13:50

标签: angular angular-ng-if

是否可以在Angular 2中使用* ngIf控制3个div?

我可以做点什么吗

<div *ngIf="planState=plan1">show plan 1</div>

<div *ngIf="planState=plan2">show plan 2</div>

<div *ngIf="planState=plan3">show plan 3</div>

谢谢!

3 个答案:

答案 0 :(得分:1)

你只是错过了比较运算符,它应该只是target-dir而不是Set-ADUser $newUser -UserPrincipalName $UserPrincipalName

您也可以使用 [隐藏] 。建议在[隐藏]之前使用ngIf

==

=

答案 1 :(得分:1)

我已更新您的plunker代码,如下所示:

@Component({
  selector: 'my-app',
  template: `
  <button (click)="OnButtonClick(1)">select - 1</button>
  <button (click)="OnButtonClick(2)">select - 2</button>
  <button (click)="OnButtonClick(3)">select - 3</button>
  <h5>You selected : {{value}}</h5>

  <hr>
  <div>
     <div *ngIf="value==1">1. Template - <b>{{value}}</b> </div>
     <div *ngIf="value==2">2. Template - <b>{{value}}</b> </div>
     <div *ngIf="value==3">3. Template - <b>{{value}}</b> </div>
     <div *ngIf="value==0">Default Template</div>

  </div>
  `,

})
export class AppComponent {
  value:number=0;

  OnButtonClick(value)
  {
    this.value=value
  }
}

答案 2 :(得分:1)

您可以在角度2中使用 * ngIf ,它等效于角度的ng-if