如何將ng-bootstrap(由angular-ui Team編寫)添加到Angular-CLI(Angular2 RC4)項目中?如何將ng-bootstrap添加到Angular-CLI(Broccoli版本)項目中?
更具體地說:
- 我應該如何從我的node_modules文件夾中添加縮小的的CSS我的角CLI項目?
- 我必須將它添加到angular-cli-build.js嗎?
- 我必須添加類型嗎?
- 我必須將它添加到/src/system-config.ts
如何將ng-bootstrap(由angular-ui Team編寫)添加到Angular-CLI(Angular2 RC4)項目中?如何將ng-bootstrap添加到Angular-CLI(Broccoli版本)項目中?
更具體地說:
是你必須在angular-cli-build.js
文件 從vendorNpmFiles引用添加所有你的CSS文件中第一次去到項目目錄和類型
npm install --save @ng-bootstrap/ng-bootstrap
然後打開你的角CLI-build.js和加入這一行
vendorNpmFiles: [
'systemjs/dist/system-polyfills.js',
'systemjs/dist/system.src.js',
'zone.js/dist/**/*.+(js|js.map)',
'es6-shim/es6-shim.js',
'reflect-metadata/**/*.+(ts|js|js.map)',
'rxjs/**/*.+(js|js.map)',
'@angular/**/*.+(js|js.map)',
'angularfire2/**/*.js',
'firebase/*.js',
'@ng-bootstrap/ng-bootstrap/**/*.+(js|js.map)'
]
現在打開你的src /系統的conf ig.ts,寫
const map: any = {
'@ng-bootstrap/ng-bootstrap': 'vendor/@ng-bootstrap/ng-bootstrap'
};
和
const packages: any = {
'@ng-bootstrap/ng-bootstrap': {
defaultExtension: 'js',
main: 'index.js'
},
'@ng-bootstrap/ng-bootstrap/accordion': {
defaultExtension: 'js',
main: 'index.js'
},
'@ng-bootstrap/ng-bootstrap/alert': {
defaultExtension: 'js',
main: 'index.js'
},
'@ng-bootstrap/ng-bootstrap/buttons': {
defaultExtension: 'js',
main: 'index.js'
},
'@ng-bootstrap/ng-bootstrap/carousel': {
defaultExtension: 'js',
main: 'index.js'
},
'@ng-bootstrap/ng-bootstrap/collapse': {
defaultExtension: 'js',
main: 'index.js'
},
'@ng-bootstrap/ng-bootstrap/dropdown': {
defaultExtension: 'js',
main: 'index.js'
},
'@ng-bootstrap/ng-bootstrap/pagination': {
defaultExtension: 'js',
main: 'index.js'
},
'@ng-bootstrap/ng-bootstrap/popover': {
defaultExtension: 'js',
main: 'index.js'
},
'@ng-bootstrap/ng-bootstrap/progressbar': {
defaultExtension: 'js',
main: 'index.js'
},
'@ng-bootstrap/ng-bootstrap/rating': {
defaultExtension: 'js',
main: 'index.js'
},
'@ng-bootstrap/ng-bootstrap/tabset': {
defaultExtension: 'js',
main: 'index.js'
},
'@ng-bootstrap/ng-bootstrap/timepicker': {
defaultExtension: 'js',
main: 'index.js'
},
'@ng-bootstrap/ng-bootstrap/tooltip': {
defaultExtension: 'js',
main: 'index.js'
},
'@ng-bootstrap/ng-bootstrap/typeahead': {
defaultExtension: 'js',
main: 'index.js'
}
};
是深受@pd法哈德上述回答,但我想給一些解釋的那一個,
其實,如果你要添加一些第三方庫angular CLI那麼您必須在angular-cli-build.js文件中添加該第三方庫引用,因爲角度cli將供應商文件夾中的所有文件取而代之node_modules
文件夾,所以只要你在cli-build文件中爲你的庫添加條目(在你的情況下說ng-bootstrap)。它會在角度cli的供應商文件夾中複製該庫。這對我們的項目是可用的。所以
How should I add the minified .css from my node_modules folder to my angular-cli project?
你必須給,才能在供應商文件夾來獲得在system-cli-build.js
文件的文件/庫的參考。
Do I have to add it to angular-cli-build.js
是,它的強制性,如果它是圖書館,而不是僅僅在單個文件的情況下,比你可以刪除該文件到公用文件夾了。它取決於你。
Do I have to add the typings?
沒有太多的強制性。
希望這清除更多!
很好解釋。非常感謝這個解釋。我是否可以知道爲什麼它不是強制要求添加類型?添加AngularFire2需要添加類型。那麼添加或不添加什麼樣的決定因素? –
非常感謝您的讚賞,對我來說意味着很多:)抱歉,我無法確切瞭解,只要我知道我會在現有答案中發佈或編輯 –
編輯答案,因爲它要求由角度ui團隊編寫的ng-bootstrap。它並不是要求Valore Software提供的ng2-bootstrap。看到這裏的差異。 https://www.reddit.com/r/Angular2/comments/4s3kkx/what_is_the_difference_between_ngbootstrap/ –
@ pd-farhad當我設置'預編譯:[NGB_PRECOMPILE]'我得到了以下錯誤:bootstrap-angular/tmp/broccoli_type_script_compiler-input_base_path -djYaKive.tmp/0/src/app/app.component.ts(8,3):類型'{moduleId:string;選擇器:字符串;指令:(typeof NgbAlert | typeof NgbDismissibleAlert)[...'不能分配給類型爲'{selector?:string;輸入?:string [];輸出?:string [];屬性?:string [];事件?:嚴格......「。 對象字面量可能只指定已知屬性,'precompile'不存在於類型'{selector ?: string;輸入?:string []; outp –