How to correctly set Http Request Header in Angular 2

Your parameter for the request options in http.put() should actually be of type RequestOptions. Try something like this: let headers = new Headers(); headers.append(‘Content-Type’, ‘application/json’); headers.append(‘authentication’, `${student.token}`); let options = new RequestOptions({ headers: headers }); return this.http .put(url, JSON.stringify(student), options)

Angular2: How to load data before rendering the component?

update If you use the router you can use lifecycle hooks or resolvers to delay navigation until the data arrived. https://angular.io/guide/router#milestone-5-route-guards To load data before the initial rendering of the root component APP_INITIALIZER can be used How to pass parameters rendered from backend to angular2 bootstrap method original When console.log(this.ev) is executed after this.fetchEvent();, this … Read more

Angular: Cannot find a differ supporting object ‘[object Object]’

I think that the object you received in your response payload isn’t an array. Perhaps the array you want to iterate is contained into an attribute. You should check the structure of the received data… You could try something like that: getusers() { this.http.get(`https://api.github.com/search/users?q=${this.input1.value}`) .map(response => response.json().items) // <—— .subscribe( data => this.users = data, … Read more

Difference between HttpModule and HttpClientModule

Use the HttpClient class from HttpClientModule if you’re using Angular 4.3.x and above: import { HttpClientModule } from ‘@angular/common/http’; @NgModule({ imports: [ BrowserModule, HttpClientModule ], … class MyService() { constructor(http: HttpClient) {…} It’s an upgraded version of http from @angular/http module with the following improvements: Interceptors allow middleware logic to be inserted into the pipeline … Read more

File Upload In Angular?

Angular 2 provides good support for uploading files. No third party library is required. <input type=”file” (change)=”fileChange($event)” placeholder=”Upload file” accept=”.pdf,.doc,.docx”> fileChange(event) { let fileList: FileList = event.target.files; if(fileList.length > 0) { let file: File = fileList[0]; let formData:FormData = new FormData(); formData.append(‘uploadFile’, file, file.name); let headers = new Headers(); /** In Angular 5, including the … Read more