[英]Get ng-bootstrap to work for angular cli project with npm
我正在尝试使用ng-bootstrap工作的 angular CLI 设置项目。 但是,我根本无法让这种风格发挥作用。 这是我采取的确切步骤(这是从入门页面开始的步骤)
按照入门指南对我的 app.module.ts 文件执行以下操作
从“@ng-bootstrap/ng-bootstrap”导入 {NgbModule};
@NgModule({ 声明: [AppComponent, ...], 导入: [NgbModule.forRoot(), ...], bootstrap: [AppComponent] }) 导出类 AppModule { }
此时我的设置应该准备好了。 所以我获取日期选择器HTML 和 TS 代码,并将其放入我的 app.component.ts 和 app.compoennt.html 文件中
app.component.ts
import { Component } from '@angular/core';
import {NgbDateStruct} from '@ng-bootstrap/ng-bootstrap';
const now = new Date();
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
model: NgbDateStruct;
date: { year: number, month: number };
selectToday() {
this.model = { year: now.getFullYear(), month: now.getMonth() + 1, day: now.getDate() };
}
}
应用程序组件.html
<p>Simple datepicker</p>
<ngb-datepicker #dp [(ngModel)]="model" (navigate)="date = $event.next"></ngb-datepicker>
<hr/>
<button class="btn btn-sm btn-outline-primary" (click)="selectToday()">Select Today</button>
<button class="btn btn-sm btn-outline-primary" (click)="dp.navigateTo()">To current month</button>
<button class="btn btn-sm btn-outline-primary" (click)="dp.navigateTo({year: 2013, month: 2})">To Feb 2013</button>
<hr/>
<pre>Month: {{ date.month }}.{{ date.year }}</pre>
<pre>Model: {{ model | json }}</pre>
您需要在 bootstrap.min.css 的样式中添加 angular-cli.json
"styles": [ "styles.scss", "../node_modules/bootstrap/dist/css/bootstrap.min.css" ]
你需要在 app.module.ts 导入 Ng2BootstrapModule
@NgModule({ declarations: [AppComponent], imports: [BrowserModule, FormsModule, HttpModule, RouterModule.forRoot(routes), Ng2BootstrapModule], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.