Angular ng Bootstrap按钮组件
Angular ng bootstrap是一个与angular一起使用的bootstrap框架,用于创建具有良好风格的组件,这个框架非常容易使用,用于制作响应式网站。
在这篇文章中,我们将了解如何在angular ng bootstrap中使用按钮。按钮是用来制作一组按钮的。
安装:
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:
<br/>
<div class="btn-group btn-group-toggle">
<label class="btn-success" ngbButtonLabel>
<input type="checkbox" ngbButton>
GeeksforGeeks1
</label>
<label class="btn-warning" ngbButtonLabel>
<input type="checkbox" ngbButton>
GeeksforGeeks2
</label>
<label class="btn-danger" ngbButtonLabel>
<input type="checkbox" ngbButton>
GeeksforGeeks3
</label>
<label class="btn-info" ngbButtonLabel>
<input type="checkbox" ngbButton>
GeeksforGeeks4
</label>
<label class="btn-primary" ngbButtonLabel>
<input type="checkbox" ngbButton>
GeeksforGeeks5
</label>
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 { }
输出:
示例 2:
<br/>
<div class="btn-group btn-group-toggle">
<label class="btn-success" ngbButtonLabel>
<input type="radio">
GeeksforGeeks1
</label>
<label class="btn-warning" ngbButtonLabel>
<input type="radio">
GeeksforGeeks2
</label>
<label class="btn-danger" ngbButtonLabel>
<input type="radio">
GeeksforGeeks3
</label>
<label class="btn-info" ngbButtonLabel>
<input type="radio">
GeeksforGeeks4
</label>
<label class="btn-primary" ngbButtonLabel>
<input type="radio">
GeeksforGeeks5
</label>
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 { }
输出: