Server communication
Angular enables communication between the browser and server apps using the HTTP library, which supports both XHR and JSONP APIs. The following steps need to be taken to achieve server communication:
- Import HTTP-related modules/components inÂ
AppModule
, as follows:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ReactiveFormsModule } from '@angular/forms';
import{HttpModule,JsonpModule}from'@angular/http';
import { AppComponent } from './app.component';
import { LoginComponent } from './rlogin/login.component';
@NgModule({
imports: [ BrowserModule, ReactiveFormsModule,HttpModule,JsonpModule ],
declarations: [ AppComponent, LoginComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
- Create a service which will be delegated tasks by the components to invoke one or more APIs on the server. As a best practice...