Angular PrimeNG侧边栏全屏

Angular PrimeNG侧边栏全屏

Angular PrimeNG是一个开源框架,拥有丰富的原生Angular UI组件,可用于出色的造型,该框架可用于制作响应式网站,非常方便。在这篇文章中,我们将了解如何在Angular PrimeNG中使用Sidebar Full Screen。我们还将了解代码中使用的属性及其语法。

Sidebar组件用于制作一个重叠在屏幕边缘的元素。Sidebar fullScreen=”true”可以用来使侧边栏占满整个屏幕。

语法:

<p-sidebar 
    [(visible)]="..." 
    [fullScreen]="true">
    ...
</p-sidebar>

<p-button 
    (click)="..."
    label="...">
</p-button>

Angular PrimeNG侧边栏全屏属性s。

  • visible:它指定了对话框的可见性。它是布尔数据类型,默认值是false
  • styleClass。它用于设置组件的风格类别。它的数据类型是字符串,默认值是null
  • fullScreen。它用于在标题上添加一个关闭图标以隐藏对话框。它是布尔数据类型,默认值是false

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

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

ng new appname

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

cd appname

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

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

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

Angular PrimeNG侧边栏全屏

  • 运行下面的命令可以看到输出。
ng serve --open

示例1:下面是说明使用[fullscreen]="true"的Angular PrimeNG侧边栏全屏的示例代码。

<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Sidebar Full Screen</h5>
  
<p-sidebar 
    [(visible)]="gfg" 
    [fullScreen]="true">
    <h2>
      This is sidebar is taking 
      the full screen size
      </h2>
      
    <p-button
          type="button"
          (click)="gfg = false"
          label="OK"
          styleClass="p-button-info">
    </p-button>
  
    <p-button
          type="button"
          (click)="gfg = false"
          label="Cancel"
          styleClass="p-button-danger p-ml-2">
    </p-button>
</p-sidebar>
  
<p-button 
      (click)="gfg = true"
      label="Full Screen On!">
</p-button>
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 { BrowserAnimationsModule }
  from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { ButtonModule } from "primeng/button";
import { SidebarModule } from "primeng/sidebar";
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        SidebarModule,
        ButtonModule,
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
export class AppModule {}

输出:

Angular PrimeNG侧边栏全屏

示例2:下面是另一个示例代码,说明了Angular PrimeNG侧边栏全屏使用[fullscreen]="false"

<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Sidebar Full Screen</h5>
  
<p-sidebar 
    [(visible)]="gfg" 
    [fullScreen]="false">
    <h2>
          This is sidebar is taking 
          the default screen size
      </h2>
      
    <p-button
          type="button"
          (click)="gfg = false"
          label="OK"
          styleClass="p-button-info">
    </p-button>
  
    <p-button
          type="button"
          (click)="gfg = false"
          label="Cancel"
          styleClass="p-button-danger p-ml-2">
    </p-button>
</p-sidebar>
  
<p-button 
      (click)="gfg = true"
      label="Full Screen off!">
</p-button>
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 { BrowserAnimationsModule }
  from "@angular/platform-browser/animations";
import { AppComponent } from "./app.component";
import { ButtonModule } from "primeng/button";
import { SidebarModule } from "primeng/sidebar";
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        SidebarModule,
        ButtonModule,
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
  
export class AppModule {}

输出:

Angular PrimeNG侧边栏全屏

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程