Last active
October 4, 2019 11:58
-
-
Save muhammadawaisshaikh/d84e6585d3fa787b8c34c381bd38e546 to your computer and use it in GitHub Desktop.
data-holding-service-JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import {DataHolderService} from '../../core/services/data-holder-service/data-holder-service.service'; | |
@Component({ | |
selector: 'app-c1', | |
templateUrl: './c1.component.html', | |
styleUrls: ['./c1.component.scss'] | |
}) | |
export class C1Component implements OnInit { | |
constructor( | |
private dataHolder: DataHolderService | |
) { } | |
ngOnInit() { | |
} | |
// sending data to service for holding | |
feedDataToService(item) { | |
const data = { | |
id: item.id | |
FirstName: item.FirstName, | |
LastName: item.LastName, | |
ProfileTitle: item.ProfileTitle, | |
AdditionDes: item.AdditionDes, | |
} | |
this.dataHolder.getData(data); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit } from '@angular/core'; | |
import {DataHolderService} from '../../core/services/data-holder-service/data-holder-service.service'; | |
@Component({ | |
selector: 'app-c2', | |
templateUrl: './c2.component.html', | |
styleUrls: ['./c2.component.scss'] | |
}) | |
export class C2Component implements OnInit { | |
constructor( | |
private dataHolder: DataHolderService | |
) { } | |
ngOnInit() { | |
} | |
// getting data from DataHolderService in this component | |
getDataFromService() { | |
const data = this.dataHolder.setData(); | |
console.log(data); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class DataHolderService { | |
constructor() { } | |
data: any; | |
getData(data){ | |
this.data = { | |
id: data.id, | |
FirstName: data.FirstName, | |
LastName: data.LastName, | |
ProfileTitle: data.ProfileTitle, | |
} | |
} | |
setData() { | |
return this.data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment