Angular PrimeNG FloatLabel组件

Angular PrimeNG FloatLabel组件

Angular PrimeNG是一个开源框架,它有丰富的原生Angular UI组件,可以用来做很好的造型,这个框架用来做响应式网站,非常方便。在这篇文章中,我们将了解如何在Angular PrimeNG中使用FloatLabel组件。

FloatLabel组件是可以在输入组件上使用的浮动标签。

创建Angular应用程序并安装模块:

  • 第1步:使用以下命令创建一个Angular应用程序。
ng new appname
  • 第2步:在创建你的项目文件夹即appname后,使用以下命令移动到它。
cd appname
  • 第3步:在你给定的目录中安装PrimeNG。
npm install primeng --save
npm install primeicons --save

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

Angular PrimeNG FloatLabel组件

例子1:这是一个基本的例子,说明如何使用FloatLabel组件。

<h2>GeeksforGeeks</h2>
  
<p>PrimeNG FloatLabel component</p>
  
<div class="p-field p-col-12 p-md-4">
  <span class="p-float-label">
    <input type="text" pInputText />
    <label>InputText</label>
  </span>
</div>
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule } from "@angular/forms";
import { BrowserAnimationsModule } from
    "@angular/platform-browser/animations";
import { HttpClientModule } from "@angular/common/http";
  
import { AppComponent } from "./app.component";
  
import { AutoCompleteModule } from "primeng/autocomplete";
import { InputTextModule } from "primeng/inputtext";
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    AutoCompleteModule,
    FormsModule,
    HttpClientModule,
    InputTextModule,
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

输出:

Angular PrimeNG FloatLabel组件

例子2:在这个例子中,我们将知道如何在FloatLabel组件中使用disabled属性。

<h2>GeeksforGeeks</h2>
  
<p>PrimeNG FloatLabel component</p>
  
<div class="p-field p-col-12 p-md-4">
  <span class="p-float-label">
    <input disabled="true" type="text" pInputText />
    <label>InputText</label>
  </span>
</div>
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { FormsModule } from "@angular/forms";
import { BrowserAnimationsModule } from 
    "@angular/platform-browser/animations";
import { HttpClientModule } from "@angular/common/http";
  
import { AppComponent } from "./app.component";
  
import { AutoCompleteModule } from "primeng/autocomplete";
import { InputTextModule } from "primeng/inputtext";
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    AutoCompleteModule,
    FormsModule,
    HttpClientModule,
    InputTextModule,
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

输出:

Angular PrimeNG FloatLabel组件

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程