1
我正在使用Angular2和語義UI,我想創建一個複選框,如https://jsfiddle.net/jp8xj0wk/2/,但當我使用* ngFor迭代時,複選框不會'噸的工作,但如果我手動插入複選框項目只有這些工作正常。複選框不適用於角2和語義UI中的ngfor
import { Component, OnInit, Input } from '@angular/core';
declare var $: any;
@Component({
selector: 'combo-multiple',
template: `
<div class="ui basic right labeled dropdown icon button">
<i class="dropdown icon"></i>
<span class="ui tiny header">Items</span>
<div class="menu">
<div class="ui icon search input">
<i class="search icon"></i>
<input type="text" name="search" placeholder="Search...">
</div>
<div class="scrolling menu">
<!-- Checkbox inserted manually works fine -->
<div class="ui checkbox item" data-value="item -1">
<input type="checkbox" name="item-1">
<label>item-1</label>
</div>
<div class="ui checkbox item" data-value="item 0">
<input type="checkbox" name="item0">
<label>item0</label>
</div>
<!-- End. Checkbox inserted manually works fine -->
<!-- checkbox with ngFor doesn't work -->
<div class="ui checkbox item" *ngFor="let item of items" [attr.data-value]="item">
<input type="checkbox" name="{{item}}">
<label>{{item}}</label>
</div>
</div>
</div>
`
})
export class ComboMultiple implements OnInit {
items: string[];
constructor() {}
ngOnInit() {
this.items = ["Item 1","Item 2","Item 3"];
$('.ui.checkbox').checkbox();
$('.ui.dropdown').dropdown({action:'nothing'});
}
}
嗨,感謝您的幫助,但它不起作用。我對ngOnInit和ngAfterViewInit有相同的結果。 –
好吧,從字面上複製粘貼你的代碼到這個plunkr:https://plnkr.co/edit/sW12Fn3FFCWmxYkznWAO?p=preview。工作得很好.. –
嘗試選擇一些迭代項目,你會發現這是行不通的,這些項目是不可點擊的。同時我把一些CSS放在複選框寬度:100%和高度:100%; –