Skip to content

Instantly share code, notes, and snippets.

@splincode
Created May 16, 2020 15:23
Show Gist options
  • Save splincode/1d0507144961879251dc549bb212c54c to your computer and use it in GitHub Desktop.
Save splincode/1d0507144961879251dc549bb212c54c to your computer and use it in GitHub Desktop.
interface UserModel {
id: number | null;
username: string | null;
age: number | null;
}
@StateRepository()
@State<UserModel>({
name: 'userInfo',
defaults: {
id: null,
username: null,
age: null
}
})
@Injectable()
export class UserInfoState extends NgxsDataRepository<UserModel> {
}
@Component()
export class UserComponent {
constructor(private userInfo: UserInfoState, private userApi: UserService) {
}
public ngOnInit(): void {
this.userApi.load().subscribe((user: UserModel) => this.userInfo.setState(user));
}
public ngOnDestroy() {
this.userInfo.reset();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment