Angular PrimeNG Steps只读
Angular PrimeNG是一个开源框架,拥有丰富的原生Angular UI组件,可以用来做很好的造型,这个框架用来制作响应式网站非常方便。在这篇文章中,我们将学习如何在Angular PrimeNG中使用Steps Readonly。我们还将学习这些属性,以及它们在代码中的语法。
步骤组件用于指示或跟踪一系列过程的完成情况。只读属性用于检查项目是否可以点击。
语法:
<p-steps
[model]="..."
[(activeIndex)]="..."
[readonly]="...">
</p-steps>
创建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 Steps Readonly使用readonly="true"。
- app.component.html:
<h2>GeeksforGeeks</h2>
<h4>PrimeNG Steps ReadOnly</h4>
<p-steps
[model]="geeks"
[(activeIndex)]="gfg" [readonly]="true">
</p-steps>
- app.component.ts:
import { Component } from "@angular/core";
import { MenuItem } from "primeng/api";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
})
export class AppComponent {
geeks: MenuItem[];
gfg: number = 0;
ngOnInit() {
this.geeks = [
{ label: "PrimeNG" },
{ label: "AngularJS" },
{ label: "ReactJS" },
{ label: "HTML" },
];
}
}
- app.module.ts:
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { RouterModule } from "@angular/router";
import { BrowserAnimationsModule }
from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { StepsModule } from "primeng/steps";
import { ToastModule } from "primeng/toast";
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
StepsModule,
ToastModule,
RouterModule.forRoot([{
path: "",
component: AppComponent
}]),
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
输出:

例子2:这是一个基本的例子,说明了如何使用Angular PrimeNG Steps Readonly使用readonly="false"。
- app.component.html:
<h2>GeeksforGeeks</h2>
<h4>PrimeNG Steps ReadOnly</h4>
<p-steps
[model]="geeks"
[(activeIndex)]="gfg" [readonly]="false">
</p-steps>
- app.component.ts:
import { Component } from "@angular/core";
import { MenuItem } from "primeng/api";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
})
export class AppComponent {
geeks: MenuItem[];
gfg: number = 0;
ngOnInit() {
this.geeks = [
{ label: "PrimeNG" },
{ label: "AngularJS" },
{ label: "ReactJS" },
{ label: "HTML" },
];
}
}
- app.module.ts:
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { RouterModule } from "@angular/router";
import { BrowserAnimationsModule }
from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { StepsModule } from "primeng/steps";
import { ToastModule } from "primeng/toast";
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
StepsModule,
ToastModule,
RouterModule.forRoot([{
path: "",
component: AppComponent
}]),
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
输出:

极客教程