I'm using an angular 4 application.
Here I have two components, one is for add functionality and another one is for view functionality.
I need to refresh the content in view page whenever i added a new item. The thing i'm doing here is calling the function present in view page at the time of adding a new item.
Here the function is calling and i'm getting the new data source for view page. But the problem here is, the view page Html is not updating. It doesn't showing the new item in the list even i updated the data source.
Any Help ?
Thanks!
** This is an add request component ts**
`import { Component, OnInit } from '@angular/core';
import { GlobalService } from '../../shared/services/global.service';
import{RequestHistoryComponent}from'./pages/request-history/requesthistory.component';
@Component({
selector: 'app-create-request-popup',
templateUrl: './create-request-popup.component.html',
styleUrls: ['./create-request-popup.component.scss'],
providers:[RequestHistoryComponent]
})
export class CreateRequestComponent implements OnInit {
constructor(private _globalService:GlobalService,private ReqHisComp:RequestHistoryComponent) {
this.AddServiceReq();
}
ngOnInit(){}
RequsetOBJ=[];
AddServiceReq(){
this._globalService.postApi("ServiceRequest",this.RequsetOBJ).subscribe(response=>{
console.log(response);
if(response.Status=="OK"){
** // This is the function in another compontent **
this.ReqHisComp.GetallServicerequests();
}
},err=>{
console.log(err);
});
}
}`
This is view requests component ts
`import { Component, OnInit } from '@angular/core';
import { GlobalService } from '../../shared/services/global.service';
@Component({
selector: 'app-request-history',
templateUrl: './request-history.component.html',
styleUrls: ['./request-history.component.scss']
})
export class RequestHistoryComponent implements OnInit {
constructor(private _globalService:GlobalService) {
this.GetallServicerequests();
}
ngOnInit(){}
MainReqData: any = undefined;
GetallServicerequests() {
this.MainReqData=undefined;
console.log(this.MainReqData);
this._globalService.getApi("RequestList?CustomerMasterId=" + this.CustomerMasterId + "&AgentMasterId=" + this.AgentMasterId + "&ServiceProviderMasterId=" + this.ServiceProviderMasterId + "&ServiceRequestStatusId=null&ServicePlanId=null").subscribe(response => {
console.log("GetAllRequest", response);
if (response.length > 0 && response != undefined) {
this.MainReqData=response;
}else{
this.MainReqData=[];
}
},err=>{
console.log(err);
})
}
}`