前端學習(2335):angular之內建結構指令ngif

小歌謠發表於2020-10-02

child.html

<p>child4 works!</p>

<div class="us">我是歌謠</div>
<div [ngClass]="currentClass" class="col">我是歌謠</div>

<div *ngIf="true">aaaa</div>
<div *ngIf="false">bbbbb</div>

child.ts

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-child4',
  templateUrl: './child4.component.html',
  styleUrls: ['./child4.component.css']
})
export class Child4Component implements OnInit {
currentClass(){

}
  constructor() { }

  ngOnInit(): void {
  this.currentClass={
    col:true
  }
  }

}

執行結果

 

相關文章