Angular PrimeNG PickList响应式
Angular PrimeNG是一个开源框架,拥有丰富的原生Angular UI组件,可用于出色的造型,这个框架用于制作响应式网站,非常容易。
Angular PrimeNG PickList用于在不同的列表之间重新排序,并且在响应模式下,picklist会根据屏幕大小调整其控件。要激活这种模式,请将响应性设置为true。
语法:
<p-pickList [responsive]="true">
HTML
创建Angular应用程序和模块安装。
第1步:使用以下命令创建一个Angular应用程序。
ng new appname
JavaScript
第2步:创建你的项目文件夹即appname后,使用以下命令移动到它。
cd appname
JavaScript
第3步在你给定的目录中安装PrimeNG。
npm install primeng --save
npm install primeicons --save
npm install @angular/cdk --save
JavaScript
项目结构:它将看起来像如下。
例子1:在这个例子中,我们将看到一个设定好的响应性属性
product.ts
export interface Product {
id?: string;
code?: string;
name?: string;
description?: string;
price?: number;
quantity?: number;
inventoryStatus?: string;
category?: string;
image?: string;
rating?: number;
}
JavaScript
app.component.html
<div style="width:80%">
<h1 style="color:green">GeeksforGeeks</h1>
<h2>Angular PrimeNG PickList Responsive</h2>
<p-pickList ="sourceProducts"
[target]="targetProducts" [dragdrop]="true"
[responsive]="true"
[sourceStyle]="{'height':'300px'}"
[targetStyle]="{'height':'300px'}"
style="width:50%">
<ng-template let-product pTemplate="item">
<div class="product-item">
<div class="product-list-detail">
<h5 class="mb-2">{{product.name}}</h5>
<img [src]="product.image" s
style="display:inline-block;
margin:2px 0 2px 2px"
width="48">
<span class="product-category">
{{product.category}}
</span>
</div>
<div class="product-list-action">
<h6 class="mb-2">
Rs {{product.price}}
</h6>
</div>
</div>
</ng-template>
</p-pickList>
</div>
HTML
app.component.css
.product-item {
display: flex;
align-items: center;
padding: .5rem;
width: 100%;
color:white;
background-color: green;
}
img {
width: 75px;
box-shadow: 0 3px 6px
rgba(0, 0, 0, 0.16), 0 3px 6px
rgba(0, 0, 0, 0.23);
margin-right: 1rem;
}
.product-list-detail {
flex: 1 1 0;
}
.product-list-action {
display: flex;
flex-direction: column;
align-items: flex-end;
}
HTML
app.component.ts
import { Component } from '@angular/core';
import { Product } from './product';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
data: Product[] = [
{
"id": "1000",
"code": "GFG111",
"name": "JAVA",
"description": "Programming language",
"image":
'https://media.geeksforgeeks.org/wp-content/cdn-uploads/Java.png',
"price": 6500,
},
{
"id": "1001",
"code": "GFG555",
"name": "Angular JS",
"description": "Front End Development",
"image":
'https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210322182256/AngularJS-Tutorial.png',
"price": 700,
},
{
"id": "1002",
"code": "GFG777",
"name": "CSS",
"description": "Style Sheet",
"image":
'https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210203171024/CSSTutorial.png',
"price": 2900,
},
{
"id": "1003",
"code": "GFG999",
"name": "HTML",
"description": "HTML Development",
"image":
'https://media.geeksforgeeks.org/wp-content/cdn-uploads/20220401124017/HTML-Tutorial.png',
"price": 3100,
},
]
sourceProducts: Product[] = this.data;
targetProducts: Product[] = [];
}
JavaScript
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { PickListModule } from 'primeng/picklist';
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
PickListModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
JavaScript
输出:
实例2:在这个例子中,我们将看到响应性是如何与头文件和过滤器等属性一起工作的。
product.ts
export interface Product {
id?: string;
code?: string;
name?: string;
description?: string;
price?: number;
quantity?: number;
inventoryStatus?: string;
category?: string;
image?: string;
rating?: number;
}
JavaScript
app.component.html
<div style="width:80%">
<h1 style="color:green">GeeksforGeeks</h1>
<h2>Angular PrimeNG PickList Responsive</h2>
<p-pickList ="sourceProducts"
[target]="targetProducts"
targetHeader="Target List"
[dragdrop]="true"
[responsive]="true"
[sourceStyle]="{'height':'300px'}"
[metaKeySelection]="true"
sourceHeader="Source List"
filterBy="name"
sourceFilterPlaceholder="Search by name"
targetFilterPlaceholder="Search by name"
[targetStyle]="{'height':'300px'}"
style="width:50%">
<ng-template let-product pTemplate="item">
<div class="product-item">
<div class="product-list-detail">
<h5 class="mb-2">{{product.name}}</h5>
<img [src]="product.image"
style="display:inline-block;
margin:2px 0 2px 2px"
width="48">
<span class="product-category">
{{product.category}}
</span>
</div>
<div class="product-list-action">
<h6 class="mb-2">
Rs {{product.price}}
</h6>
</div>
</div>
</ng-template>
</p-pickList>
</div>
HTML
app.component.css
.product-item {
display: flex;
align-items: center;
padding: 0.5rem;
width: 100%;
color: white;
background-color: green;
}
img {
width: 75px;
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16),
0 3px 6px rgba(0, 0, 0, 0.23);
margin-right: 1rem;
}
.product-list-detail {
flex: 1 1 0;
}
.product-list-action {
display: flex;
flex-direction: column;
align-items: flex-end;
}
HTML
app.component.ts
import { Component } from '@angular/core';
import { Product } from './product';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
data: Product[] = [
{
"id": "1000",
"code": "GFG111",
"name": "JAVA",
"description": "Programming language",
"image":
'https://media.geeksforgeeks.org/wp-content/cdn-uploads/Java.png',
"price": 6500,
},
{
"id": "1001",
"code": "GFG555",
"name": "Angular JS",
"description": "Front End Development",
"image":
'https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210322182256/AngularJS-Tutorial.png',
"price": 700,
},
{
"id": "1002",
"code": "GFG777",
"name": "CSS",
"description": "Style Sheet",
"image":
'https://media.geeksforgeeks.org/wp-content/cdn-uploads/20210203171024/CSSTutorial.png',
"price": 2900,
},
{
"id": "1003",
"code": "GFG999",
"name": "HTML",
"description": "HTML Development",
"image":
'https://media.geeksforgeeks.org/wp-content/cdn-uploads/20220401124017/HTML-Tutorial.png',
"price": 3100,
},
]
sourceProducts: Product[] = this.data;
targetProducts: Product[] = [];
}
JavaScript
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { PickListModule } from 'primeng/picklist';
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
PickListModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
JavaScript
输出: