After capturing data from one component, I am attempting to transfer it to another component through a service.
Component1 (Start) : radio box View
<md-radio-button
*ngIf="item.id===1"
value="{{item.value}}"
class="{{item.class}}"
checked="{{item.checked}}"
(click)="onSelectType1(item)"> //capturing the value here
{{item.label}}
</md-radio-button>
ts code
public onSelectType1(selected:any){
this.formeService.type1Change(selected.nb)
}
SERVICE :
@Injectable()
export class FormeService{
public type1S : any;
public type1Change(selected):any
{
this.type1S=selected; //storing it in the service here
}
Component 2 : (End) : Simple View
ts code
export class ContentComponent{
constructor(public BackService : BackgroundService ,
public formeService: FormeService)
{
console.log(this.formeService.type1S)
////// displays as undefined in the console !!!!!!!!!!!!!!!!!
The issue lies HERE: how can I access the value of my variable in this section?
}
!!!!!!!! and meanwhile in the view it shows me the value:
{{formeService.type1S}} // normal functionality here
Can someone advise on how I can display the data value in the "end component ts code"?