Angular PrimeNG Inplace 基础
Angular PrimeNG是一个开源框架,拥有丰富的原生Angular UI组件,可以用来做很好的造型,这个框架用来制作响应式网站非常方便。本文将告诉我们如何在Angular PrimeNG中使用Inplace Basic。我们还将学习属性、事件、方法和造型,以及代码中使用的语法。
Inplace组件用于同时编辑和显示其他内容,并在点击按钮显示时渲染实际输出。
语法:
<p-inplace closable="closable">
....
</p-inplace>
Angular PrimeNG Inplace 基本属性:
- closable。它显示一个按钮来切换回显示模式。它是布尔数据类型,默认值是false。
创建Angular应用程序和模块安装。
第1步:使用以下命令创建一个Angular应用程序。
ng new appname
第2步:创建你的项目文件夹即appname后,使用以下命令移动到它。
cd appname
第3步在你给定的目录中安装PrimeNG。
npm install primeng --save
npm install primeicons --save
项目结构:它将看起来像如下。
运行以下命令以查看输出:
ng serve --open
例子1:下面是说明使用Angular PrimeNG Inplace Basic的例子代码。
<div style="text-align: center">
<h2 style="color: green">GeeksforGeeks</h2>
<h5>Angular PrimeNG Inplace Basic</h5>
<p-inplace closable="closable">
<ng-template
pTemplate="display">
Click here geek
</ng-template>
<ng-template pTemplate="content">
<input type="text"
value="GeeksforGeeks"
pInputText />
</ng-template>
</p-inplace>
</div>
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { CarService } from './carservice';
import { InplaceModule } from 'primeng/inplace';
import { TableModule } from 'primeng/table';
import { InputTextModule } from 'primeng/inputtext';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
InplaceModule,
InputTextModule,
TableModule,
HttpClientModule,
],
declarations: [AppComponent],
bootstrap: [AppComponent],
providers: [CarService],
})
export class AppModule {}
输出:
例子2:下面是另一个例子代码,说明了Angular PrimeNG Inplace Basic的使用。
<div style="text-align: center">
<h2 style="color: green">GeeksforGeeks</h2>
<h5>Angular PrimeNG Inplace Basic</h5>
<p-inplace>
<ng-template pTemplate="display">
Click Here Geek
</ng-template>
<ng-template pTemplate="content">
<p-button>GeeksforGeeks</p-button>
</ng-template>
</p-inplace>
</div>
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { CarService } from './carservice';
import { InplaceModule } from 'primeng/inplace';
import { TableModule } from 'primeng/table';
import { InputTextModule } from 'primeng/inputtext';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
InplaceModule,
InputTextModule,
TableModule,
HttpClientModule,
],
declarations: [AppComponent],
bootstrap: [AppComponent],
providers: [CarService],
})
export class AppModule {}
输出: