Когда я делаю запрос к контроллеру Web Api
this.http.get("https://localhost:44354/api/home/5",{responseType: 'text' })
.subscribe(result => { console.log(result); });
в консоли result
Я получаю
SyntaxError: Неожиданный конец ввода↵
в AppComponent.push ../ src / app / app.component.ts.AppComponent.setTitle (http://localhost:4200/main.js:137:14)↵
в Object.eval [как handleEvent] (ng: ///AppModule/AppComponent.ngfactory.js: 13: 27)101
в handleEvent (http://localhost:4200/vendor.js:67178:41)↵
в callWithDebugContext (http://localhost:4200/vendor.js:68272:25)↵
в Object.debugHandleEvent [as handleEvent] (http://localhost:4200/vendor.js:67975:12)↵
в dispatchEvent (http://localhost:4200/vendor.js:64627:25)↵
в http://localhost:4200/vendor.js:65074:38↵
в HTMLButtonElement. (http://localhost:4200/vendor.js:74051:36)↵
в ZoneDelegate.push ../ node_modules / zone.js / dist / zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:2766:31)↵
в Object.onInvokeTask (http://localhost:4200/vendor.js:61652:33)
Как заставить Angular 6 распознавать строку?
Startup.cs
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseCors(builder => builder.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin().AllowCredentials());
app.UseMvc();
}
}
app.component.ts
import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
responsText: string;
constructor(private http: HttpClient) {
}
setTitle(): void {
this.http.get("https://localhost:44354/api/home/5",{responseType: 'text' })
.subscribe(result => { console.log(result); });
debugger;
}
}
HomeController
[Route("api/[controller]")]
public class HomeController : Controller
{
// GET api/<controller>/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
}