{"id":3026,"date":"2019-02-21T14:27:26","date_gmt":"2019-02-21T14:27:26","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=3026"},"modified":"2020-04-29T18:23:50","modified_gmt":"2020-04-29T18:23:50","slug":"angular-simple-application","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/angular-simple-application\/","title":{"rendered":"Angular Simple Application"},"content":{"rendered":"<p><strong>Interpolation<\/strong><br \/>\n<strong>app.component.ts<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nimport { Component } from '@angular\/core';\r\n\r\n@Component({\r\n  selector: 'app-root',\r\n  templateUrl: '.\/app.component.html',\r\n  styleUrls: &#x5B;'.\/app.component.css']\r\n})\r\nexport class AppComponent {\r\n  title = 'schoolApp';\r\n}\r\n<\/pre>\n<p><strong>registration.component.html<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;div style=&quot;text-align:center&quot;&gt;\r\n  &lt;h1&gt;\r\n    Welcome to {{ title }}!\r\n  &lt;\/h1&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<p><\/p>\n<p>Looping through Model Object set in component and Printing in HTML Page<br \/>\n<strong>Student.ts<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nexport class Student {\r\n   public isPresent:boolean=true;\r\n\r\n   constructor(public studentId:number,\r\n               public studentName:string,\r\n               public studentAge:number,\r\n               public studentGender:boolean){}\r\n               \r\n\r\n    getAttendance():string{\r\n       if(this.isPresent==true)\r\n        return &quot;P&quot;;\r\n       else \r\n        return &quot;A&quot;;\r\n    }           \r\n}\r\n\r\n<\/pre>\n<p><strong>registration.component.ts<\/strong><\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nimport { Component, OnInit } from '@angular\/core';\r\nimport {Student} from '..\/model\/student';\r\n\r\n@Component({\r\n  selector: 'app-registration',\r\n  templateUrl: '.\/registration.component.html',\r\n  styleUrls: &#x5B;'.\/registration.component.css']\r\n})\r\nexport class RegistrationComponent implements OnInit {\r\n  public arrStudent:Array&lt;Student&gt;;\r\n  constructor() { }\r\n\r\n  ngOnInit() {\r\n     this.arrStudent = &#x5B;new Student(101, 'Mugil', 31, true),\r\n                        new Student(102, 'Manasa', 26, false),\r\n                        new Student(103, 'Kavitha', 27, false),\r\n                        new Student(104, 'Renu', 28, true),\r\n                        new Student(105, 'Joseph', 23, true)];\r\n  }\r\n\r\n  getGender(Student):string\r\n  {\r\n    if(Student.studentGender==true)\r\n     return &quot;M&quot;;\r\n     else\r\n     return &quot;F&quot;;\r\n  }\r\n}\r\n<\/pre>\n<p><strong>registration.component.html<\/strong><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;style&gt;\r\n .even\r\n    {\r\n        background-color: rgb(235, 235, 235);\r\n    }\r\n\r\n    .odd\r\n    {\r\n        background-color : #ffffff;\r\n    }\r\n&lt;\/style&gt;\r\n&lt;table cellpadding=&quot;5&quot;&gt;\r\n    &lt;thead&gt;\r\n  &lt;tr&gt;\r\n    &lt;th&gt;Sno&lt;\/th&gt;\r\n    &lt;th&gt;Student ID&lt;\/th&gt;\r\n    &lt;th&gt;Name&lt;\/th&gt;\r\n    &lt;th&gt;Age&lt;\/th&gt;\r\n    &lt;th&gt;Gender&lt;\/th&gt;\r\n    &lt;th&gt;Attendance&lt;\/th&gt;\r\n  &lt;\/tr&gt;\r\n&lt;\/thead&gt;\r\n&lt;tbody&gt;\r\n  &lt;tr *ngFor=&quot;let objStudent of arrStudent; index as i;even as isEven;odd as isOdd&quot; &#x5B;class]=&quot;isEven?'even':'odd'&quot;&gt;\r\n     &lt;td&gt;{{i+1}}&lt;\/td&gt;\r\n     &lt;td&gt;{{objStudent.studentId}}&lt;\/td&gt;\r\n     &lt;td&gt;{{objStudent.studentName}}&lt;\/td&gt;\r\n     &lt;td&gt;{{objStudent.studentAge}}&lt;\/td&gt;\r\n     &lt;td&gt;{{ getGender(objStudent) }}&lt;\/td&gt;\r\n     &lt;td &#x5B;class]=&quot;objStudent.isPresent?'present':'absent'&quot;&gt;{{objStudent.getAttendance()}}&lt;\/td&gt; \r\n  &lt;\/tr&gt;\r\n&lt;\/tbody&gt;\r\n&lt;\/table&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/codethataint.com\/blog\/wp-content\/uploads\/2019\/02\/Angular_Output1.png\" height=\"165\" width=\"323\"\/> <\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Interpolation app.component.ts import { Component } from &#8216;@angular\/core&#8217;; @Component({ selector: &#8216;app-root&#8217;, templateUrl: &#8216;.\/app.component.html&#8217;, styleUrls: &#x5B;&#8217;.\/app.component.css&#8217;] }) export class AppComponent { title = &#8216;schoolApp&#8217;; } registration.component.html &lt;div style=&quot;text-align:center&quot;&gt; &lt;h1&gt; Welcome to {{ title }}! &lt;\/h1&gt; &lt;\/div&gt; Looping through Model Object set in component and Printing in HTML Page Student.ts export class Student { public isPresent:boolean=true; constructor(public&hellip; <a href=\"https:\/\/codethataint.com\/blog\/angular-simple-application\/\">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":[259],"tags":[],"class_list":["post-3026","post","type-post","status-publish","format-standard","hentry","category-code-examples"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3026","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=3026"}],"version-history":[{"count":5,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3026\/revisions"}],"predecessor-version":[{"id":3696,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/3026\/revisions\/3696"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=3026"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=3026"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=3026"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}