{"id":3728,"date":"2020-05-13T13:46:47","date_gmt":"2020-05-13T13:46:47","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=3728"},"modified":"2020-05-13T14:21:59","modified_gmt":"2020-05-13T14:21:59","slug":"directives-basics","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/directives-basics\/","title":{"rendered":"Directives Basics"},"content":{"rendered":"<p><strong class=\"ctaHeader3\">If Else<\/strong><br \/>\n<strong>aboutus.component.ts<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nexport class AboutusComponent implements OnInit {\r\n  showMsg: boolean = true;\r\n  .\r\n  .\r\n  .\r\n}\r\n<\/pre>\n<p><strong>aboutus.component.html<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;p *ngIf='showMsg; else elseBlock'&gt;aboutus works from If block!&lt;\/p&gt;\r\n\r\n&lt;ng-template #elseBlock&gt;\r\n    &lt;p&gt;aboutus works from else block!&lt;\/p&gt;\r\n&lt;\/ng-template&gt;\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<pre>\r\naboutus works from If block!\r\n<\/pre>\n<p><strong class=\"ctaHeader3\">Switch Case<\/strong><br \/>\n<strong>aboutus.component.ts<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nexport class AboutusComponent implements OnInit {\r\n  .\r\n  .\r\n  color : string =  'pink';\r\n  .\r\n  .\r\n}\r\n<\/pre>\n<p><strong>aboutus.component.html<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div &#x5B;ngSwitch] = 'color'&gt;\r\n    &lt;p *ngSwitchCase=&quot;'blue'&quot;&gt;Its Blue Color&lt;\/p&gt;\r\n    &lt;p *ngSwitchCase=&quot;'red'&quot;&gt;Its Red Color&lt;\/p&gt;\r\n    &lt;p *ngSwitchCase=&quot;'green'&quot;&gt;Its Green Color&lt;\/p&gt;    \r\n    &lt;p *ngSwitchDefault&gt;Its Default Color&lt;\/p&gt;    \r\n&lt;\/div&gt;\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<pre>\r\nIts Default Color\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>If Else aboutus.component.ts export class AboutusComponent implements OnInit { showMsg: boolean = true; . . . } aboutus.component.html &lt;p *ngIf=&#8217;showMsg; else elseBlock&#8217;&gt;aboutus works from If block!&lt;\/p&gt; &lt;ng-template #elseBlock&gt; &lt;p&gt;aboutus works from else block!&lt;\/p&gt; &lt;\/ng-template&gt; Output aboutus works from If block! Switch Case aboutus.component.ts export class AboutusComponent implements OnInit { . . color : string =&hellip; <a href=\"https:\/\/codethataint.com\/blog\/directives-basics\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[300],"tags":[],"class_list":["post-3728","post","type-post","status-publish","format-standard","hentry","category-directives"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3728","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=3728"}],"version-history":[{"count":4,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3728\/revisions"}],"predecessor-version":[{"id":3732,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3728\/revisions\/3732"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=3728"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=3728"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=3728"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}