Angular PrimeNG Form Dropdown Disabled Options Component
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use the calendar component in angular ngx bootstrap.
Dropdown Disabled Options Component: This is used to disable any component by using optionDisabled property.
Syntax:
<p-dropdown optionDisabled="inactive"></p-dropdown>
Creating Angular Application & Module Installation:
Step 1: Create an Angular application using the following command.
ng new appname
Step 2: After creating your project folder i.e. appname, move to it using the following command.
cd appname
Step 3: Install PrimeNG in your given directory.
npm install primeng --save npm install primeicons --save
Project Structure:
Example 1: In the below code, we will be using the above syntax to demonstrate the use of the Angular PrimeNG Form Dropdown Disabled Options Component.
app.component.html
HTML
< div style = "text-align:center;" > < h1 style = "color:green;" > w3wiki </ h1 > < h3 >A computer science portal for Beginner</ h3 > < h4 > Angular PrimeNG Form Dropdown Disabled Options Component </ h4 > < p-dropdown [options]="cities" [(ngModel)]="selectedCity" optionLabel = "name" optionDisabled = "inactive" > </ p-dropdown > </ div > |
app.component.ts
HTML
import { Component } from '@angular/core'; import { MenuItem } from 'primeng/api'; import { SelectItem } from 'primeng/api'; import { SelectItemGroup } from 'primeng/api'; interface City { name: string, code: string, inactive: boolean } @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'], }) export class AppComponent { cities: City[]; selectedCity: City; constructor() { this.cities = [ { name: 'India', code: 'IND', inactive: false }, { name: 'Rome', code: 'RM', inactive: true }, { name: 'London', code: 'LDN', inactive: false }, { name: 'Istanbul', code: 'IST', inactive: true }, { name: 'Paris', code: 'PRS', inactive: false }, ]; } } |
app.module.ts
Javascript
import { NgModule } from '@angular/core' ; import { BrowserModule } from '@angular/platform-browser' ; import { FormsModule } from '@angular/forms' ; import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ; import { AppComponent } from './app.component' ; import { DropdownModule } from 'primeng/dropdown' ; @NgModule({ imports: [ BrowserModule, BrowserAnimationsModule, DropdownModule, FormsModule ], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule { } |
app.component.scss
:host ::ng-deep .p-dropdown { width: 14rem; }
Output:
Example 2: In the below code, we will be using the above syntax to demonstrate the use of the Angular PrimeNG Form Dropdown Disabled Options Component.
app.component.html
HTML
< div style = "text-align:center;" > < h1 style = "color:green;" >w3wiki</ h1 > < h3 >A computer science portal for Beginner</ h3 > < h4 > Angular PrimeNG Form Dropdown Disabled Options Component </ h4 > < p-dropdown [options]="cities" [(ngModel)]="selectedCity" optionLabel = "name" optionDisabled = "inactive" > </ p-dropdown > </ div > |
app.component.ts
Javascript
import { Component } from '@angular/core' ; import { MenuItem } from 'primeng/api' ; import { SelectItem } from 'primeng/api' ; import { SelectItemGroup } from 'primeng/api' ; interface City { name: string, code: string, inactive: boolean } @Component({ selector: 'app-root' , templateUrl: './app.component.html' , styleUrls: [ './app.component.scss' ], }) export class AppComponent { cities: City[]; selectedCity: City; constructor() { this .cities = [ { name: 'India' , code: 'IND' , inactive: true }, { name: 'Rome' , code: 'RM' , inactive: true }, { name: 'London' , code: 'LDN' , inactive: true }, { name: 'Istanbul' , code: 'IST' , inactive: true }, { name: 'Paris' , code: 'PRS' , inactive: true }, ]; } } |
app.module.ts
Javascript
import { NgModule } from '@angular/core' ; import { BrowserModule } from '@angular/platform-browser' ; import { FormsModule } from '@angular/forms' ; import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ; import { AppComponent } from './app.component' ; import { DropdownModule } from 'primeng/dropdown' ; @NgModule({ imports: [ BrowserModule, BrowserAnimationsModule, DropdownModule, FormsModule ], declarations: [AppComponent], bootstrap: [AppComponent] }) export class AppModule { } |
app.component.scss
:host ::ng-deep .p-dropdown { width: 14rem; }
Output:
Contact Us