This project was generated with Angular CLI version 10.1.7.
Run ng serve
for a dev server. Navigate to http://localhost:4200/
. The app will automatically reload if you change any of the source files.
改造service从api获取数据
- 将StudentService上的getStudents和getStudent方法用HttpClient改造
- 修改StudentListComponent和StudentDetailComponent组件的Init钩子方法,改为订阅http返回的结果。
- 捕获getStudent的异常并
改造app添加NgRx状态管理工具来维护数据
- 创建loadStudent和setStudent的ActionCreator。
- 创建StudentReducer,需要响应loadStudents和setStudents Action。
- 修改StudentListComponent和StudentDetailComponent组件,不注入Service改为注入Store,订阅Store上的selector来获取数据。
- StudentListComponent的Init钩子中dispatch出loadStudents Action。
- 创建LoadStudentEffect监听loadStudents Action,调用StudentService的getStudents方法从api获取数据,输出setStudents Action。
- 在AppModule中加载StoreModule和EffectsModule模块。