【发布时间】:2017-06-11 13:53:39
【问题描述】:
我正在尝试使用 ng-bootstrap 工作的角度 CLI 设置项目。但是,我根本无法让这种风格发挥作用。这是我采取的确切步骤(这是入门页面中的步骤)
- 使用 -ng new testApp 创建一个新项目
- 根据 ng-bootstrap 的入门页面,我需要预先安装 bootstrap 4。所以我运行 npm install bootstrap@4.0.0-alpha.6
- 然后我运行 npm install --save @ng-bootstrap/ng-bootstrap
-
按照入门指南对我的 app.module.ts 文件执行以下操作
从'@ng-bootstrap/ng-bootstrap'导入{NgbModule};
@NgModule({ 声明:[AppComponent, ...], 进口:[NgbModule.forRoot(), ...], 引导程序:[AppComponent] }) 导出类 AppModule { }
此时我的设置应该已准备就绪。所以我抓取了Date Picker 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() };
}
}
app.component.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>
【问题讨论】:
-
您是否在任何地方引用了引导 CSS?如果使用 angular-cli,您可以将其添加到 angular-cli.json 文件中的“脚本”数组中。在您为 angular 2 bootstrap 提供的链接中,它提到 Bootstrap CSS 作为依赖项。
-
我添加到 angular-cli 并且它有效,谢谢。很惊讶入门指南中没有提到它....
-
呸……我说的是“脚本”……我的意思是“样式”。无论哪种方式,我都同意。它肯定会避免一些混乱!
标签: javascript css twitter-bootstrap angular typescript