{"id":1042,"date":"2023-06-06T05:00:00","date_gmt":"2023-06-06T12:00:00","guid":{"rendered":"https:\/\/www.angulartraining.com\/daily-newsletter\/?p=1042"},"modified":"2023-06-04T19:00:31","modified_gmt":"2023-06-05T02:00:31","slug":"using-a-loading-template-with-ngrxlet","status":"publish","type":"post","link":"https:\/\/www.angulartraining.com\/daily-newsletter\/using-a-loading-template-with-ngrxlet\/","title":{"rendered":"Using a loading template with ngrxLet"},"content":{"rendered":"\n<p>A while back, I wrote about how <a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/ngrxlet-a-better-version-of-the-async-pipe\/\" target=\"_blank\" rel=\"noopener\" title=\"\"><code>ngrxLet<\/code> is an improved version of the async pipe<\/a>. I also covered how to use <a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/skeleton-loaders-with-angular\/\" target=\"_blank\" rel=\"noopener\" title=\"\">skeleton loaders with Angular<\/a>.<\/p>\n\n\n\n<p>Today, let&#8217;s look at how we can use these two tools to display a &#8220;loading&#8221; template while an observable is waiting for data.<\/p>\n\n\n\n<p>As a reminder, here is how <code>ngrxLet<\/code> can be used to <a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/skeleton-loaders-with-angular\/\" target=\"_blank\" rel=\"noopener\" title=\"\">track different observable events<\/a>:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-1024x307.png\" alt=\"\" class=\"wp-image-1043\" width=\"540\" height=\"161\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-1024x307.png 1024w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-300x90.png 300w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-768x230.png 768w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image.png 1200w\" sizes=\"auto, (max-width: 540px) 100vw, 540px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>In the above code snippet, we receive the values emitted by the <code>number$<\/code> observable in a variable <code>n<\/code>. We would receive any error in a variable <code>e<\/code>. We would receive the completion status (<code>true<\/code> or <code>false<\/code>) in a variable <code>c<\/code>.<\/p>\n\n\n\n<p>Here is how we can pass a custom loading template to <code>ngrxLet<\/code> using a <a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/template-reference-variables\/\" target=\"_blank\" rel=\"noopener\" title=\"\">template reference variable<\/a>:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-1-1024x328.png\" alt=\"\" class=\"wp-image-1044\" width=\"528\" height=\"169\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-1-1024x328.png 1024w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-1-300x96.png 300w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-1-768x246.png 768w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-1.png 1104w\" sizes=\"auto, (max-width: 528px) 100vw, 528px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>Of course, the loading template can be customized with anything you want, including a skeleton loader or an animated gif image. That feature is called a <a href=\"https:\/\/ngrx.io\/guide\/component\/let#using-suspense-template\" target=\"_blank\" rel=\"noopener\" title=\"\">suspense template<\/a>, and an observable is in a suspense state until it emits its first event (<code>next<\/code>, <code>error<\/code>, or <code>complete<\/code> as covered <a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/rxjs-subscribe-callback-functions\/\" target=\"_blank\" rel=\"noopener\" title=\"\">here<\/a>). <\/p>\n","protected":false},"excerpt":{"rendered":"<p>A while back, I wrote about how ngrxLet is an improved version of the async pipe. I also covered how to use skeleton loaders with Angular. Today, let&#8217;s look at how we can use these two tools to display a &#8220;loading&#8221; template while an observable is waiting for data. As a reminder, here is how [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,11,7,17],"tags":[],"class_list":["post-1042","post","type-post","status-publish","format-standard","hentry","category-components","category-directives","category-template-syntax","category-tools"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1042","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/comments?post=1042"}],"version-history":[{"count":2,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1042\/revisions"}],"predecessor-version":[{"id":1046,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1042\/revisions\/1046"}],"wp:attachment":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/media?parent=1042"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/categories?post=1042"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/tags?post=1042"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}