官术网_书友最值得收藏!

Null guarding with *ngIf

The idea strategy will be to use *ngIf, which is a structural directive, meaning Angular will stop traversing DOM tree elements beyond a falsy statement.

In the CurrentWeather component, we can easily check to see whether the current variable is null or undefined before attempting to render the template:

  1. Update the topmost p element with *ngIf to check whether current is an object, as shown:
src/app/current-weather/current-weather.component.html
<p *ngIf="current">
...
</p>

Now observe the console log and that no errors are being reported. You always ensure that your Angular application reports zero console errors. If you're still seeing errors in the console log, ensure that you have correctly reverted the OpenWeather URL to its correct state or kill and restart your npm start process. I highly recommend that you resolve any console errors before moving on. Once you've fixed all errors, ensure that you commit your code again.

  1. Commit your code.
主站蜘蛛池模板: 漠河县| 南汇区| 邵阳市| 永丰县| 洛川县| 响水县| 化州市| 无极县| 格尔木市| 鄂托克前旗| 铁岭县| 扎鲁特旗| 桐乡市| 清徐县| 藁城市| 中超| 都安| 阿瓦提县| 昔阳县| 得荣县| 海口市| 互助| 邵武市| 鲁甸县| 翁牛特旗| 建阳市| 丰台区| 庆阳市| 循化| 崇阳县| 凤凰县| 台州市| 平果县| 濮阳县| 和田县| 疏勒县| 郁南县| 四子王旗| 长岛县| 梅州市| 资中县|