componentA.ts:動態更新[選中]在Angular2
@Input() array;
<input type="checkbox" [checked]="array | contains: value"/>
<label>{{array.length}}</label>
componentB.ts:
@Component({
selector: 'app-component-b',
templateUrl: './app.component-b.html'
})
export class AppComponentB {
array = [1, 2, 3];
}
我更新在一些其他組件array
。雖然label
正確更新數組的長度,但複選框似乎未被更新。 contains
只是一個簡單的管道,用於檢查value
是否爲array
的一部分。我在contains
管道中放置了一個console.log
,並且只在頁面呈現時纔得到輸出,而不是在array
更改時獲得輸出。爲什麼是這樣?
謝謝..
你能告訴哪兒數組定義?它在服務還是組件? – micronyks
這只是組件中的一個變量。我在上面添加了一些代碼。 – 7ball