Created
May 16, 2020 15:23
-
-
Save splincode/1d0507144961879251dc549bb212c54c to your computer and use it in GitHub Desktop.
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
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