我是关于Angular的新手。我看过几个地方,大多数例子都非常复杂。有什么简单的东西可以从我开始吗?调用web api的东西,它接受2个参数并返回一个对象
[HttpPost("GetHomePageData")]
public HomePageData GetHomePageData(int P1, int P2)
{
//
}
public class HomePageData
{
public int AddressCount { get; set; }
}
答案 0 :(得分:1)
在Angular's official documentation中,您可以看到以下示例:
@Component(...)
export class MyComponent implements OnInit {
results: string[];
// Inject HttpClient into your component or service.
constructor(private http: HttpClient) {}
ngOnInit(): void {
// Make the HTTP request:
this.http.get('/api/items').subscribe(data => {
// Read the result field from the JSON response.
this.results = data['results'];
});
}
}