屬性繫結 (Property Binding)


Template語法:

<element [屬性]="變數名稱"></element>
<element 屬性="{{變數名稱}}"></element>

程式碼範例:

1.在Component.ts中加入變數placeholderText

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

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

  placeholderText = '請輸入文字';

  constructor() { }

  ngOnInit() {
  }

}

2.在Template中使用屬性繫結該變數

<input type="text" [placeholder]="placeholderText"> <button>確定</button>
<input type="text" placeholder="{{placeholderText}}"> <button>確定</button>

results matching ""

    No results matching ""