{"flag":true,"single":true,"pageTitle":"convert html code to angular","post":{"id":142,"user_id":"1","slug":"convert-html-code-to-angular-mtnv","title":"convert html code to angular","body":"<p>Here is sample html code that will be converted to angular<br><br><\/p>\r\n<pre class=\"language-markup\"><code>&lt;script src=\"assets\/js\/choices.js\"&gt;&lt;\/script&gt;\r\n\r\n&lt;div class=\"input-field second-wrap\"&gt;\r\n\t&lt;div class=\"input-select\"&gt;\r\n  \t\t&lt;select data-trigger=\"\" name=\"choices-single-defaul\"&gt;\r\n\t    \t&lt;option&gt;Coupons&lt;\/option&gt;\r\n\t    \t&lt;option&gt;Deals&lt;\/option&gt;\r\n\t  &lt;\/select&gt;\r\n\t&lt;\/div&gt;\r\n&lt;\/div&gt; \r\n\r\n&lt;script&gt;\r\n\tconst choices = new Choices('[data-trigger]',\r\n  \t{\r\n\t\tsearchEnabled: false\r\n  \t});\r\n&lt;\/script&gt;<\/code><\/pre>\r\n<p><strong>To angular<\/strong><br>To convert the given code to Angular, you need to create an Angular component and modify the HTML template and component class accordingly. Here's an example of how you can convert the code:<\/p>\r\n<p>1.Install choices.js library<\/p>\r\n<pre class=\"language-markup\"><code>npm install choices.js --save<\/code><\/pre>\r\n<p>2.Modify the choices.component.html template:<\/p>\r\n<pre class=\"language-markup\"><code>&lt;div class=\"input-field second-wrap\"&gt;\r\n    &lt;div class=\"input-select\"&gt;\r\n      &lt;select #selectElem&gt;\r\n        &lt;option *ngFor=\"let option of options\"&gt;{{ option }}&lt;\/option&gt;\r\n      &lt;\/select&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/div&gt;<\/code><\/pre>\r\n<p>3. Modify the choices.component.ts component class:<\/p>\r\n<pre class=\"language-markup\"><code>import { Component,ElementRef,ViewChild,ViewEncapsulation } from '@angular\/core';\r\nimport Choices from 'choices.js';\r\n@Component({\r\n  selector: 'app-main',\r\n  templateUrl: '.\/main.component.html',\r\n  styleUrls: ['.\/main.component.css']\r\n})\r\nexport class MainComponent {\r\n  @ViewChild('selectElem')\r\n  selectElem!: ElementRef;\r\n  options = ['Coupons', 'Deals'];\r\n  choices: any;\r\n\r\n  ngAfterViewInit(): void {\r\n    console.log(this.selectElem);\r\n    this.choices = new Choices(this.selectElem.nativeElement, {\r\n      searchEnabled: false\r\n    });\r\n  }\r\n}<\/code><\/pre>\r\n<p>4.Use the ChoicesComponent in your desired Angular component or module by adding it to the appropriate template or module.<\/p>","category_id":"13","is_private":"0","created_at":"2023-05-15T02:44:10.000000Z","updated_at":"2023-05-15T05:12:21.000000Z","category":{"id":13,"user_id":"1","name":"Angular","slug":"angular-rfjp","parent_id":"12","created_at":"2023-03-24T03:25:15.000000Z","updated_at":"2023-03-24T03:25:15.000000Z"},"user":{"id":1,"name":"R GONDAL","email":"rizikmw@gmail.com","email_verified_at":null,"two_factor_confirmed_at":null,"current_team_id":"1","profile_photo_path":null,"created_at":"2023-03-12T10:49:33.000000Z","updated_at":"2025-01-10T12:59:00.000000Z","profile_photo_url":"https:\/\/ui-avatars.com\/api\/?name=R+G&color=7F9CF5&background=EBF4FF"}},"pageDesc":"Here is sample html code that will be converted to angular &lt;script src=\"assets\/js\/choices.js\"&gt;&lt;\/script&gt;  &lt;div class=\"input-fi - convert html code to angular (Updated: May 15, 2023) - Read more about convert html code to angular at my programming site [SITE]","categories":[]}