Skip to content

Instantly share code, notes, and snippets.

@splincode
Last active May 17, 2020 18:52
Show Gist options
  • Save splincode/de2d3ed54c86701db489ce287fb56532 to your computer and use it in GitHub Desktop.
Save splincode/de2d3ed54c86701db489ce287fb56532 to your computer and use it in GitHub Desktop.
@StateRepository()
@State({
name: 'courses',
defaults: createEntityCollections()
})
@Injectable()
export class CoursesEntitiesState extends NgxsDataEntityCollectionsRepository<Course> {}
@StateRepository()
@State({
name: 'lessons',
defaults: createEntityCollections()
})
@Injectable()
export class LessonEntitiesState extends NgxsDataEntityCollectionsRepository<Lesson> {}
@Component({
selector: 'app'
// ..
})
export class AppComponent implements OnInit {
constructor(private courses: CoursesEntitiesState, private api: ApiCoursesService) {}
public ngOnInit(): void {
this.api.getCourses().subscribe((courses: Course[]) => {
this.courses.setAll(courses);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment