【发布时间】:2020-01-04 07:21:15
【问题描述】:
我需要有关如何获取选定值并将其连接到我的“service.ts”中的 url 的帮助,然后使用将 url 放置在我的 component.ts 中的函数。我知道如何将 component.html 中的数据绑定到 component.ts,但我想知道的是绑定到 service.ts。请参阅下面的代码:
component.html
<select class="browser-default custom-select" [(ngModel)]="bindSelect">
<option value="" selected disabled>Choose item</option>
<option [value]="mydata.name" *ngFor="let mydata of vList$">
<td>{{ mydata.id }} - {{ mydata.name }}</td>
</option>
</select>
service.ts
export class ItenService {
constructor(private http: HttpClient) { }
myUrl = 'http://localhost:4045/store/itemList';
valueFromSelect = '';
getData() {
return this.http.get<itemData[]>('http://localhost:4045/store/itemList/' + this.valueFromSelect);
}
}
component.ts
export class ItemComponent implements OnInit {
vList$ = [];
bindSelect = '';
constructor(private idataService: IdataService) { }
ngOnInit() {
this.getImpl();
}
getImpl() {
// impl service.ts function here
}
}
如何将“valueFromSelect”从.html绑定到service.ts,这样当我选择item时,值绑定到valueFromSelect = ' ';
谢谢
【问题讨论】:
标签: html angular http angular8