I've have a problem when using subjects in Angular 2. I get the following error when running the app:
Type '{}' is not assignable to type 'UserDevice[]'.)
- I have a component with a list of userDevices.
- And a service which provides the userDevices.
// Service
export class UserDeviceLocalService {
udSubject = new ReplaySubject();
tmpUserDevices: UserDevice[] = [];
constructor() {
}
createUserDevices(userDevice){
this.tmpUserDevices.push(userDevice);
// localStorage.setItem('userdevices', JSON.stringify(this.tmpUserDevices));
this.udSubject.next(this.tmpUserDevices);
}
}
// component
export class UserDeviceMenuComponent implements OnInit {
userDevices: UserDevice[];
constructor(private userDeviceLocalService: UserDeviceLocalService) {
}
ngOnInit() {
this.userDeviceLocalService.udSubject.subscribe(userDevices => this.userDevices = userDevices);
}