在我的asp.net核心angular应用中,运行dotnet watch run命令时会生成两个localhost路径。那我该如何创建http服务呢?

时间:2019-03-05 02:37:56

标签: angular asp.net-core

在我的asp.net核心angular应用程序中,当运行dotnet watch run命令时会生成两个localhost路径。那我该如何创建http服务呢?

enter image description here

1 个答案:

答案 0 :(得分:0)

对于成角度的 HttpClient ,您可以通过 @Inject('BASE_URL')进行解析。

 从'@ angular / core'导入{组件,注入};
从'@ angular / common / http'导入{HttpClient};

@零件({
选择器:“ app-fetch-data”,
templateUrl:“ ./ fetch-data.component.html”
})
导出类FetchDataComponent {
私有http:HttpClient;
private baseUrl:字符串;
构造函数(http:HttpClient,@Inject('BASE_URL')baseUrl:字符串){
    http.post (this.baseUrl +“ api / SampleData / Authenticate”,{
    电子邮件,
    密码
    })。subscribe(result => {

    });
 }
}