我正在嘗試使用角度CLI與ng-bootstrap工作來設置項目。但是,我無法讓風格工作。下面是我帶的具體步驟(這是從一開始啓動頁面步驟)獲取ng-bootstrap爲nil角度cli項目工作
- 創建使用一個新的項目 - 納克新testApp
- 根據NG-引導的開始頁面,我需要引導程序4預裝。所以我來說NPM安裝[email protected]
- 然後我跑NPM安裝--save @ NG-引導/ NG-引導
按照新手指南,並做了以下我的應用程序。 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文件中的「scripts」數組中。在您爲angular 2引導提供的鏈接中,它提到了Bootstrap CSS作爲依賴關係。 – silencedmessage
我添加到angular-cli,它的工作表示感謝。感到驚訝的是,它沒有在入門指南中提到.... – user172902
Bah ..我說「腳本」...我的意思是「風格」。無論哪種方式,我同意。這肯定會避免一些混亂! – silencedmessage