2

近期收获总结

 3 years ago
source link: https://segmentfault.com/a/1190000040549104
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

近期收获总结

发布于 8 月 20 日

1、近期,首先学会并实践了使用GitHub桌面版,从mian分支拉取更新数据,创建自己的任务分支号并进行开发,最后上传自己写的代码到GitHub上。

2、publish上传文件时,一定要把测试用的“fit”改回“it”。

3、习惯运行时打开页面控制台,出错时,先仔细看并翻译控制台报错的叙述,根据叙述找出问题所在。

4、多利用控制台打印日志来验证某文件是否正确执行。
eg:
lALPDg7mRg7d26_NAyLNB1c_1879_802.png
要实现community的add功能,却报错如上图所示,经过排查不是第一种错误(api文件与service文件的url相同),现利用控制台打印日志来检测出错原因。
先梳理数据流问题:
add.component.ts中“this.communityService.save(newCommunity)”执行调用community.service.ts的save方法,M层调用HttpClient向模拟后台mockApi发起请求,执行community.api.ts文件。
首先在service打印日志发现控制台显示,进而在api文件打印日志,并未显示,表明api文件并未起作用,则转入下列第5点。

5、写了某文件后,要在相应的配置文件中加入声明。
eg:写了community.api.ts文件,要在api.testing.module.ts中加入import,以及要在provider数组中加入CommunityApi。
ps:后期,api.testing.module.ts文件改写为:

@NgModule({
  imports: [
    HttpClientModule
  ],
  providers: [
    {provide: CommonService, useClass: CommonStubService},
    {
      provide: HTTP_INTERCEPTORS, multi: true, useClass: MockApiTestingInterceptor.forRoot(apis)
    }]
})

指向apis文件,则把写的api文件(CommunityApi)相应地加入到apis.ts文件中即可。

6、html文件中

<tr *ngFor="let object of pageData.content; index as i">
  <td>{{pageData.number * pageData.size + i + 1}}</td>

这样写后,分页时每一页就不单单又是1~pageData.size排序,而是从所有数据的1~n排序。即下图所示:
image.png

7、常见问题之一:
ng t 后得到如下错误:
image.png
类似这种NullInjectorError: No provider for xxx,一般就是spec.ts文件中缺少某个模块的import。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK