Angular PrimeNG Inplace Image

Angular PrimeNG Inplace Image

Angular PrimeNG是一个开源框架,拥有丰富的原生Angular UI组件,可用于出色的造型,该框架可用于制作响应式网站,非常方便。本文将向我们展示如何在Angular PrimeNG中使用Inplace Image。我们还将学习属性、事件、方法和造型,以及代码中使用的语法。

Inplace组件用于同时编辑和显示其他内容,并在点击按钮显示时渲染实际输出。

语法:

<p-inplace>
  <ng-template pTemplate="display">
      ...... 
  </ng-template>

  <ng-template pTemplate="content">
    ......
  </ng-template>
</p-inplace>

创建Angular应用程序和模块安装。

第1步:使用以下命令创建一个Angular应用程序。

ng new appname

第2步:创建你的项目文件夹即appname后,使用以下命令移动到它。

cd appname

第3步在你给定的目录中安装PrimeNG。

npm install primeng --save
npm install primeicons --save

项目结构:它将看起来像如下。

Angular PrimeNG Inplace Image

运行以下命令以查看输出:

ng serve --open

例子1:下面是说明使用Angular PrimeNG Inplace Image的例子代码。

<div style="text-align: center">
  <h2 style="color: green">GeeksforGeeks</h2>
  <h5>Angular PrimeNG Inplace Image</h5>
  
  <p-inplace>
    <ng-template pTemplate="display">
      Click here for DSA-Self Pace
    </ng-template>
  
    <ng-template pTemplate="content">
      <img
        width="300px"
        height="300px"
        alt="gfg" src=
"https://media.geeksforgeeks.org/img-practice/banner/dsa-self-paced-course-overview-image.png?v=1661743919" />
    </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 {}

输出:

Angular PrimeNG Inplace Image

例子2:下面是另一个例子代码,说明了Angular PrimeNG Inplace Image的使用。

<div style="text-align: center">
  <h2 style="color: green">GeeksforGeeks</h2>
  <h5>Angular PrimeNG Inplace Image</h5>
  
  <p-inplace>
    <ng-template pTemplate="display">
      Click here for System Design
    </ng-template>
  
    <ng-template pTemplate="content">
      <img
        width="300px"
        height="300px"
        alt="gfg" src=
"https://media.geeksforgeeks.org/img-practice/banner/system-design-live-course-overview-image.png?v=1661744378" />
    </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 {}

输出:

Angular PrimeNG Inplace Image

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程