{"id":1073,"date":"2023-06-15T05:00:00","date_gmt":"2023-06-15T12:00:00","guid":{"rendered":"https:\/\/www.angulartraining.com\/daily-newsletter\/?p=1073"},"modified":"2023-06-14T17:08:21","modified_gmt":"2023-06-15T00:08:21","slug":"new-control-flow-rfc","status":"publish","type":"post","link":"https:\/\/www.angulartraining.com\/daily-newsletter\/new-control-flow-rfc\/","title":{"rendered":"New control flow RFC"},"content":{"rendered":"\n<p>One of the major announcements on day 1 of <a href=\"https:\/\/ng-conf.org\/\" target=\"_blank\" rel=\"noopener\" title=\"\">ng-conf<\/a> was the <a href=\"https:\/\/github.com\/angular\/angular\/discussions\/50719\" target=\"_blank\" rel=\"noopener\" title=\"\">control flow request for comments (RFC)<\/a>.<\/p>\n\n\n\n<p>We&#8217;re all familiar with <code>ngFor<\/code>, <code>ngIf<\/code>, <code>ngSwitch<\/code>, and their syntaxes can get tricky at times.<\/p>\n\n\n\n<p>Now what if <code>ngIf<\/code> was replaced with:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-13.png\" alt=\"\" class=\"wp-image-1074\" width=\"240\" height=\"113\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-13.png 390w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-13-300x142.png 300w\" sizes=\"auto, (max-width: 240px) 100vw, 240px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>And what if the new syntax supported much more than <code>ngIf<\/code>, such as <code>else if<\/code> and even readable <code>else<\/code> cases:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-14.png\" alt=\"\" class=\"wp-image-1075\" width=\"332\" height=\"246\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-14.png 518w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-14-300x222.png 300w\" sizes=\"auto, (max-width: 332px) 100vw, 332px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>The goal of the Angular team is to introduce syntaxes that are closer to regular Javascript and remove the need for these structural directives.<\/p>\n\n\n\n<p><code>for<\/code> loops would look like this and even support a <code>empty<\/code> template. All current <a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/ngfor-local-variables\/\" target=\"_blank\" rel=\"noopener\" title=\"\"><code>ngFor<\/code> local variables<\/a> would be available automatically with <a href=\"https:\/\/github.com\/angular\/angular\/discussions\/50719#:~:text=Within%20for%20row%20views,variables%20are%20always%20available\" target=\"_blank\" rel=\"noopener\" title=\"\">no need for variable aliasing<\/a>, too:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-15.png\" alt=\"\" class=\"wp-image-1076\" width=\"430\" height=\"150\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-15.png 860w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-15-300x105.png 300w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-15-768x270.png 768w\" sizes=\"auto, (max-width: 430px) 100vw, 430px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>Finally, <code>ngSwitch<\/code> would become the following:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-16.png\" alt=\"\" class=\"wp-image-1077\" width=\"295\" height=\"354\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-16.png 448w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-16-250x300.png 250w\" sizes=\"auto, (max-width: 295px) 100vw, 295px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>Angular CLI would perform the syntax updates throughout your Angular code, so there is no need to worry about rewriting those templates. You can find all the reasons why the Angular team decided on these syntaxes compared to other options in the <a href=\"https:\/\/github.com\/angular\/angular\/discussions\/50719\" target=\"_blank\" rel=\"noopener\" title=\"\">RFC<\/a>. You&#8217;re, of course, welcome to add your comments and suggestions to the list.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the major announcements on day 1 of ng-conf was the control flow request for comments (RFC). We&#8217;re all familiar with ngFor, ngIf, ngSwitch, and their syntaxes can get tricky at times. Now what if ngIf was replaced with: And what if the new syntax supported much more than ngIf, such as else if [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,7],"tags":[],"class_list":["post-1073","post","type-post","status-publish","format-standard","hentry","category-angular","category-template-syntax"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1073","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=1073"}],"version-history":[{"count":2,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1073\/revisions"}],"predecessor-version":[{"id":1079,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1073\/revisions\/1079"}],"wp:attachment":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/media?parent=1073"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/categories?post=1073"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/tags?post=1073"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}