Angular ng Bootstrap塌陷组件

Angular ng Bootstrap塌陷组件

Angular ng bootstrap是一个与angular一起使用的bootstrap框架,用于创建具有良好风格的组件,这个框架非常容易使用,用于制作响应式网站。

在这篇文章中,我们将了解如何在angular ng bootstrap中使用Collapse。Collapse是用来制作一个按钮,点击它就可以折叠起来。

安装:

ng add @ng-bootstrap/ng-bootstrap

步骤:

  • 首先,使用上述命令安装angular ng bootstrap。
  • 在module.ts中导入ng bootstrap模块
    import { NgbModule } from '@ng-bootstrap/ng-bootstrap';

    imports: [
      NgbModule
    ]

  • 在app.component.html中制作一个折叠组件。
  • 使用ng serve为应用程序提供服务。

例子1:在这个例子中,我们正在制作一个基本的塌陷组件。

<p>
  <br/>
  <button type="button"
          class="btn btn-success" 
          (click)="collapse.toggle()" 
          [attr.aria-expanded]="!gfg"
    aria-controls="collapseExample">
    Click to collapse
  </button>
</p>
  
<div #collapse="ngbCollapse" 
     [(ngbCollapse)]="gfg">
  <div class="card">
    <div class="card-body">
      Angular10 ng bootstrap
    </div>
  </div>
</div>
import { NgModule } from '@angular/core';
  
// Importing forms module
import { FormsModule, ReactiveFormsModule  }
from '@angular/forms';
import { BrowserModule } 
from '@angular/platform-browser';
import { BrowserAnimationsModule } 
from '@angular/platform-browser/animations';
   
import { AppComponent }  
from './app.component';
import { NgbModule }
from '@ng-bootstrap/ng-bootstrap';
   
@NgModule({
  bootstrap: [
    AppComponent
  ],
  declarations: [
    AppComponent
  ],
  imports: [
    FormsModule,
    BrowserModule,
    BrowserAnimationsModule,
    ReactiveFormsModule,
    NgbModule
  ]
})
export class AppModule { }
import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent {
    public gfg = false;
}

输出:

Angular ng Bootstrap塌陷组件

例子2:在这个例子中,我们已经预先折叠了这个组件。

<p>
  <br/>
  <button type="button"
          class="btn btn-success"
          (click)="collapse.toggle()"
          [attr.aria-expanded]="!gfg"
    aria-controls="collapseExample">
    Click to collapse
  </button>
</p>
  
<div #collapse="ngbCollapse"
     [(ngbCollapse)]="gfg">
  <div class="card">
    <div class="card-body">
      Angular10 ng bootstrap
    </div>
  </div>
</div>
import { NgModule } from '@angular/core';
  
// Importing forms module
import { FormsModule, ReactiveFormsModule  }
from '@angular/forms';
import { BrowserModule }
from '@angular/platform-browser';
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations';
  
import { AppComponent }  
from './app.component';
import { NgbModule } 
from '@ng-bootstrap/ng-bootstrap';
   
@NgModule({
  bootstrap: [
    AppComponent
  ],
  declarations: [
    AppComponent
  ],
  imports: [
    FormsModule,
    BrowserModule,
    BrowserAnimationsModule,
    ReactiveFormsModule,
    NgbModule
  ]
})
export class AppModule { }
import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent {
    public gfg = true;
}

输出:

Angular ng Bootstrap塌陷组件

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程