Angular PrimeNG TabView模板

Angular PrimeNG TabView模板

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

Angular PrimeNG为TabView组件提供了便利,该组件作为一个容器,以将内容与标签分组。TabView模板是用来给TabView组件提供模板的。模板用于设置TabView内容的标题和内容。

语法:

<p-tabPanel header="..">
  <ng-template pTemplate="content">
    <p>Content</p>
  </ng-template>
</p-tabPanel>

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

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

ng new appname

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

cd appname

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

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

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

Angular PrimeNG TabView模板

例子1:下面是一个简单的例子,演示Angular PrimeNG TabView模板的使用,我们使用标题模板来给tabview组件提供一个标题。

  • app.component.html
<h2 style="color: green">GeeksforGeeks</h2>
<h4>Angular PrimeNG Tabview Template</h4>
  
<p-tabView>
    <p-tabPanel header="Coding">
        <p>Code Here</p>
    </p-tabPanel>
    <p-tabPanel header="Web Technologies">
        <p>Learn About Web Technologies</p>
    </p-tabPanel>
    <p-tabPanel header="Articles">
        <p>Read Some Technical Articles</p>
    </p-tabPanel>
</p-tabView>
  • app.component.ts
import { Component, OnInit } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    providers: [],
})
export class AppComponent {
    constructor() { }
  
    ngOnInit() { }
}
  • 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 { TabViewModule } from 'primeng/tabview';
import { ButtonModule } from 'primeng/button';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        TabViewModule,
        ButtonModule,
        RouterModule.forRoot([
            { path: '', component: AppComponent }
        ])
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }

输出:

Angular PrimeNG TabView模板

例子2:下面是另一个例子,演示Angular PrimeNG TabView模板的使用,我们在这里使用标题和内容,在ng-templates标签的帮助下定义。

  • app.component.html
<h2 style="color: green">GeeksforGeeks</h2>
<h4>Angular PrimeNG Tabview Template</h4>
  
<p-tabView>
    <p-tabPanel header="Coding">
        <ng-template pTemplate="content">
            <p>Code Here</p>
        </ng-template>
    </p-tabPanel>
    <p-tabPanel header="Web Technologies">
        <ng-template pTemplate="content">
            <p>Learn About Web Technologies</p>
        </ng-template>
    </p-tabPanel>
    <p-tabPanel header="Articles">
        <ng-template pTemplate="content">
            Read Some Technical Articles
        </ng-template>
    </p-tabPanel>
</p-tabView>
  • app.component.ts
import { Component, OnInit } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    providers: [],
})
export class AppComponent {
    constructor() { }
  
    ngOnInit() { }
}
  • 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 { TabViewModule } from 'primeng/tabview';
import { ButtonModule } from 'primeng/button';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        TabViewModule,
        ButtonModule,
        RouterModule.forRoot([
            { path: '', component: AppComponent }
        ])
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
export class AppModule { }

输出:

Angular PrimeNG TabView模板

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程