I am not able to hit my controller method Get.
I have register.component.ts file in this I am calling dataservice's getfeed method:
ngOnInit() {
this.dataservice.getFeed('register').subscribe(result => {
}
in the data.service.ts file, I have written like:
@Injectable()
export class DataService {
constructor(private http: HttpClient) { }
getFeed(methodName: string): Observable<any> {
return this.http.get(environment.baseApiUrl + methodName);
}
}
In My environment.ts file I have:
baseApiUrl:'http://localhost:4200/api/'
And finally in RegisterController.cs I coded like:
[ApiController]
[Route("[controller]")]
public class RegisterController : ControllerBase
{
[HttpGet]
[ProducesResponseType(400)]
[ProducesResponseType(typeof(string), 500)]
public async Task<IActionResult> Get()
{
}
}
But this Get is not hitting no way. I tried different URL directly from browser, but nothing is hitting in that get method. Any idea what I am missing in my implementation?
And in my Startup.cs file i have something like this:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(name: "default", pattern: "{controller}/{action=index}/{id?}");
});
registerinregister.component.tsa variable with value of string'register'? Right now you callthis.dataservice.getFeed(register), did you mean to pass it as a stringthis.dataservice.getFeed('register')? Also what port is the api running in development? You are pointing the http request to port 4200 which is where angular in development runs, wouldn't it need to be pointed to the port of the api?