seçeneğini seçmek için varsayılan değeri ayarlayın. Bir seçeneğe varsayılan değer eklemeye çalışıyorum. Bir çeşit yer tutucu gibi olacak ve bunu yapmak için this method kullanıyorum. Saf HTML'de çalışır, ancak *ngFor
açısal 2 özelliğini kullanmaya çalışırsam, hiçbir şey seçmez.Açısal 2,
<select name="select-html" id="select-html">
<option value="0" selected disabled>Select Language</option>
<option value="1">HTML</option>
<option value="2">PHP</option>
<option value="3">Javascript</option>
</select>
Ve Açısal şablonu kullanarak: Ben Select Language
istiyorum
<select name="select" id="select" [(ngModel)]="selectLanguage">
<option *ngFor="let item of selectOption"
[selected]="item.value==0"
[disabled]="item.value==0">{{item.label}}</option>
</select>
sınıf
import {Component} from '@angular/core';
@Component({
moduleId: module.id,
selector: 'app-form-select',
templateUrl: 'default.component.html'
})
export class DefaultComponent {
private selectOption: any;
constructor() {
this.selectOption = [
{
id: 1,
label: "Select Language",
value: 0
}, {
id: 2,
label: "HTML 5",
value: 1
}, {
id: 3,
label: "PHP",
value: 2
}, {
id: 4,
label: "Javascript",
value: 3
}
]
}
}
olarak seçilecek saf HTML kullanmak Burada
kodum varsayılan değer. Bu devre dışı, ancak seçilmedi.
Bunu varsayılan değer olarak nasıl seçebilirim?
@CTN üzgünüm, sorunuzu anlamıyorum. Hangi etiket ve hangi HTML DOM? –
html etiketini etiket değerine ayarlamak istiyorum. – CTN