【发布时间】:2018-12-09 02:09:39
【问题描述】:
我的 API 操作:
[HttpGet]
public ActionResult<IEnumerable<Loan>> Get()
{
return _context.Loans;
}
Loan.cs
public class Loan
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string BorrowerName { get; set; }
public decimal RepaymentAmount { get; set; }
public decimal FundingAmount { get; set; }
}
Loan.ts
export class Loan {
constructor(
public Id : number,
public BorrowerName : string,
public RepaymentAmount : number,
public FundingAmount : number
) { }
}
loans.component.ts
我可以看到http get 确实在调用我的 API,并且它正在返回预期的数据。
import { Component, OnInit } from '@angular/core';
import {HttpClient, HttpHeaders} from '@angular/common/http';
import { Loan } from '../loan';
import { Observable } from 'rxjs';
@Component({
selector: 'app-loans',
templateUrl: './loans.component.html',
styleUrls: ['./loans.component.css']
})
export class LoansComponent implements OnInit {
loans: Loan[];
constructor(private http:HttpClient) {
this.getLoans().subscribe((loans) => {
this.loans = loans;
console.log(loans);
})
}
getLoans() {
return <Observable<Loan[]>> this.http.get('http://localhost:1113/api/loans');
}
ngOnInit() {
}
}
我在控制台中看到了这个错误:
我怎样才能弄清这个问题?
【问题讨论】:
标签: c# angular asp.net-core-webapi