我有一个数组作为集合,我想将其加载到下拉列表中,并希望在某种情况下进行默认选择,但我不知道该如何实现。
app.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-commingsoon',
templateUrl: './commingsoon.component.html',
styleUrls: ['./commingsoon.component.css']
})
export class CommingsoonComponent implements OnInit {
public collection = [];
constructor() {
for(let i = 1; i<=10 ; i++) {
this.collection.push(`Angular: ${i}`);
}
}
ngOnInit() {
}
}
Run Code Online (Sandbox Code Playgroud)
app.component.html
<select name="" id="" style="position:relative; left: 100px">
<option *ngFor="let i of collection;" value="{{i}}" [selected]="i == Angular: 2">{{ i }}</option>
</select>
Run Code Online (Sandbox Code Playgroud)
我希望下拉列表应为i == Angular:2时的选定值
我有文件控制,我正在使用 jquery 设置数据属性。但是当我提交表单时,我得到了数据属性的空值。
广告.html
<div class="field" align="left">
<span>
<h3>Upload your images</h3>
<input type="file" id="files" data-filedata="" name="files[]" multiple (change)="preview($event)" />
</span>
</div>
Run Code Online (Sandbox Code Playgroud)
Jquery代码设置数据属性
$("#files").on("change", function(e) {
e.target.setAttribute('data-filedata', 'abc');
})
Run Code Online (Sandbox Code Playgroud)
广告
preview(event) {
console.log(event.target.getAttribute('data-filedata'))
}
Run Code Online (Sandbox Code Playgroud)