要通过http GET请求获取数据并在Angular 6的Mat-Select中显示,可以按照以下步骤进行解决:
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
constructor(private http: HttpClient) { }
ngOnInit() {
this.http.get('https://example.com/api/users').subscribe(
data => {
// 将获取到的数据存储在组件的属性中
this.users = data;
},
error => {
console.log(error);
}
);
}
{{ user.email }}
在这个例子中,假设API的地址为https://example.com/api/users,并且返回的数据是一个对象数组,每个对象包含一个email属性。这些数据将存储在组件的users属性中,并通过ngFor循环来显示在Mat-Select中。
请注意,这只是一个示例,你需要根据实际情况修改代码来适应你的项目需求。