aqw*_*sez 47 sass npm twitter-bootstrap typescript angular
我正在构建一个用打字稿写的角度2应用程序.它会将bootstrap 4框架与一些自定义主题结合使用,这可能吗?
"ng2-bootstrap"npm包无法正常工作,因为它不允许我使用bootstrap css类,而是提供自定义组件.(http://github.com/valor-software/ng2-bootstrap)
在我的角度2项目中,我正在使用sass,是否可以从源代码构建bootstrap 4,因为它也使用sass进行样式化?
mah*_*ich 94
Angular2 CLI的Bootstrap4 alpha(也适用于Angular4 CLI)
如果您使用angular2 cli/angular 4 cli,请执行以下操作:
npm i bootstrap@next --save
Run Code Online (Sandbox Code Playgroud)
这将为您的项目添加bootstrap 4.
接下来去你src/style.scss
或src/style.css
文件并导入引导有:
对于style.css
/* You can add global styles to this file, and also import other style files */
@import "../node_modules/bootstrap/dist/css/bootstrap.min.css";
Run Code Online (Sandbox Code Playgroud)
对于style.scss
/* You can add global styles to this file, and also import other style files */
@import "../node_modules/bootstrap/scss/bootstrap";
Run Code Online (Sandbox Code Playgroud)
如果您使用的是scss,请确保将默认样式更改为scss .angular-cli.json
:
"defaults": {
"styleExt": "scss",
"component": {}
}
Run Code Online (Sandbox Code Playgroud)
Bootstrap JS组件
要使Bootstrap JS组件工作,您仍然需要导入bootstrap.js
到.angular-cli.json
under scripts
(这应该自动发生):
...
"scripts": ["../node_modules/jquery/dist/jquery.js",
"../node_modules/tether/dist/js/tether.js",
"../node_modules/bootstrap/dist/js/bootstrap.js"],
...
Run Code Online (Sandbox Code Playgroud)
更新2017/09/13: Boostrap 4 Beta现在使用popper.js而不是tether.js.因此,根据您使用的版本导入脚本中的tether.js(alpha)或popper.js(beta).感谢@MinorThreat的抬头
Cod*_*het 38
上面的选项可行,但我通过NPM使用这种方法:
在项目中运行从步骤1获得的NPM命令,即
npm install bootstrap@4.0.0-alpha.5 --save
安装上面的依赖项后运行以下npm命令,它将安装bootstrap模块
npm install --save @ng-bootstrap/ng-bootstrap
你可以在这里阅读更多相关信息
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
并添加NgbModule
到imports
您的应用模块将如下所示:
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
@NgModule({
declarations: [
AppComponent,
WeatherComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
NgbModule.forRoot(), // Add Bootstrap module here.
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)打开angular-cli.json并在styles数组中插入一个新条目:
"styles": [
"styles.css",
"../node_modules/bootstrap/dist/css/bootstrap.min.css"
],
Run Code Online (Sandbox Code Playgroud)打开src/app/app.component.html并添加
<alert type="success">hello</alert>
Run Code Online (Sandbox Code Playgroud)
或者如果您想使用ng警报,请将以下内容放在您的 app.component.html page
<ngb-alert [dismissible]="true">I'm a dismissible alert :) </ngb-alert>
Run Code Online (Sandbox Code Playgroud)现在运行您的项目,您应该在浏览器中看到引导程序警报消息.
Reg*_*iro 11
要使用任何需要JQuery的可视化库,请执行以下操作:
如果库没有定义文件,您可以:
现在你可以使用Typescript里面的库了;
我会建议:
index.html
归档时间: |
|
查看次数: |
62799 次 |
最近记录: |