我正在尝试组合我们使用的html模式。html如下所示
<input class="sidebarInputDevice" type="search" [list]="listidentx" placeholder="Search {{label}}..." (input)="deviceSelected($event.target.value)"> {{listidentx}}
<datalist [id]="listidentx">
<option *ngFor="let item of items">{{item.name}}</option>
</datalist>
typescript代码如下所示
import { Component, OnInit, EventEmitter, Input, Output } from '@angular/core';
@Component({
selector: 'app-select-entry',
templateUrl: './select-entry.component.html',
styleUrls: ['./select-entry.component.css']
})
export class SelectEntryComponent implements OnInit {
constructor() {
//this.listidentx='working';
}
@Input()
items:{}[] = [];
@Input()
label = '';
@Input()
listident='custom';
listidentx = 'bacon';
@Output()
valueChange: EventEmitter<number> = new EventEmitter();
ngOnInit() {
console.log(this.items);
console.log("-----");
for (var i=0;i<this.items.length;i++) {
console.log(this.items[i]);
}
console.log("^----");
}
valSelected(value) {
this.valueChange.emit(value);
}
}
我收到以下错误
ERROR TypeError: Cannot assign to read only property 'list' of object '#<HTMLInputElement>'
是否有解决方案,或者我是否可以不将列表属性设置为动态。
如果无法使属性动态化,可以确保每个组件的列表都有不同的id。