This is the content of my app.component.html file
PL Auth
Username:Password :
Generate OTP
Enter OTP :
Login
This is the code in my app.component.ts file
import { Component, OnInit } from '@angular/core';
import { Location } from '@angular/common';
import { Headers, Http, Response } from '@angular/http';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
submitted = false;
userName = '';
ngOnInit() {
}
constructor(private http: Http;) { }
private generateOtp(){
this.http.get('http://localhost:8080/generateotp/'+this.userName)
.subscribe(
(res:Response)=> {
const otpCheck = res.json();
console.log(otpCheck);
}
)
}
generateOtpSubmit() {
this.submitted = true;
this.generateOtp();
}
}
This is what's included in my app.module.ts file
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { Http } from '@angular/http';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule
],
providers: [Http],
bootstrap: [AppComponent]
})
export class AppModule { }
When I attempt to initialize any variables in
constructor(private http: Http;) { }
within app.component.ts file, an error is showing up in the browser console and the page fails to load.
Error: StaticInjectorError(AppModule)[Http -> ConnectionBackend]:
StaticInjectorError(Platform: core)[Http -> ConnectionBackend]:
NullInjectorError: No provider for ConnectionBackend!
This is a screenshot of the internal error occurrence: