I am using service for sending data from a component to other.
My service follows
import {
Injectable
} from '@angular/core';
@Injectable()
export class HomeService {
values = new Array();
setValues(values): void {
this.values = values;
}
getValues(): any[] {
return this.values;
}
}
Setting value in a component
setType(type) {
this.values["plan"] = "HMO";
this.homeService.setValues(this.values);
}
Getting value in other
ngOnInit() {
this.homeValues = this.homeService.getValues();
console.log(this.homeValues);
}
Above console printing [], how to get assigned values from service?