错误:The selector app-root did not match any elements
这个错误消息倒和 Angular 的版本没有关系。
![](https://img.haomeiwen.com/i2085791/3a226245d1ac752c.png)
index.html 里定义的 selector 必须和 App.module.ts 里定义的 AppComponent selector 一致:
![](https://img.haomeiwen.com/i2085791/5b5010b93ae78d9a.png)
![](https://img.haomeiwen.com/i2085791/c978b3c29baf1a91.png)
错误2:unhandled promise rejection
![](https://img.haomeiwen.com/i2085791/5a322a0bfaa8253c.png)
原因:
在 Angular 2 里,导入 rxjs 操作符的语法:
import 'rxjs/add/observable/fromEvent';
import 'rxjs/add/operator/pairwise';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/exhaustMap';
import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/startWith';
在 Angular 12 里,导入 rxjs 的语法应该是:
import { pairwise, map, exhaustMap, filter, startWith } from 'rxjs/operators';
错误:NullInjectorError:No provider for HttpClient
![](https://img.haomeiwen.com/i2085791/b8689575f1b804ab.png)
解决方法:
![](https://img.haomeiwen.com/i2085791/d0fbb2be13ccaed2.png)
从 @angular/common/http 里导入 HttpClientModule, 加到 app module 的 imports 区域。
错误消息:NG0303: Can't bind to 'ngForOf' since it isn't a known property of 'li'.
![](https://img.haomeiwen.com/i2085791/deb1e6ce7be8689d.png)
解决方法:从 @angular/common 里导入 CommonModule, 加到 app module 的 imports 区域。
![](https://img.haomeiwen.com/i2085791/95200a6ea50f9fc7.png)
错误:
zone.js:3382 Mixed Content: The page at 'https://jerry-infinite-scroller.stackblitz.io/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://node-hnapi.herokuapp.com/news?page=1'. This request has been blocked; the content must be served over HTTPS.
解决方法:
![](https://img.haomeiwen.com/i2085791/334bc3b316dc0b7c.png)
把 service 实现里的 http 改成 https.
更多Jerry的原创文章,尽在:"汪子熙":
![](https://img.haomeiwen.com/i2085791/97c4752c0e619c44.png)
网友评论