我正在构建一个用typescript编写的angular 2应用程序.它将使用bootstrap 4框架和一些自定义主题,这可能吗?

"ng2 bootstrap"npm包不起作用,因为它不允许我使用bootstrap css类,而是提供自定义组件.(http://github.com/valor-software/ng2-bootstrap)

在我的angular 2项目中,我正在使用sass,当它也在使用sass进行造型时,是否可以从源代码构建bootstrap 4?

推荐答案

Bootstrap4 alpha for Angular2 CLI (also works for Angular4 CLI)

如果您使用的是angular2 cli/angular 4 cli,请执行以下操作:

npm i bootstrap@next --save

这将为您的项目添加 bootstrap 4.

接下来转到您的src/style.scsssrc/style.css文件,并在那里导入 bootstrap :

For 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";

For style.scss

/* You can add global styles to this file, and also import other style files */
@import "../node_modules/bootstrap/scss/bootstrap";

如果您使用的是scss,请确保在.angular-cli.json中将默认样式更改为scss:

  "defaults": {
    "styleExt": "scss",
    "component": {}
  }

Bootstrap JS Components

要让Bootstrap JS组件正常工作,您仍然需要将bootstrap.js导入scripts (this should happen automatically)下的.angular-cli.json:

...     
"scripts": ["../node_modules/jquery/dist/jquery.js",
                  "../node_modules/tether/dist/js/tether.js",
                  "../node_modules/bootstrap/dist/js/bootstrap.js"],
...

Update 2017/09/13: Boostrap 4 Beta is now using popper.js instead of tether.js. So depending on which version you are using import either tether.js (alpha) or popper.js (beta) in your scripts.谢谢大家的提醒@MinorThreat

Typescript相关问答推荐

为什么当类类型与方法参数类型不兼容时,该函数可以接受类类型

如何让这个函数正确推断返回类型?

与Prettify助手类型中的对象相交?

之间是否有区别:例如useEffect()React.useEffect()

如何将类型从变量参数转换为返回中的不同形状?

react 路由6操作未订阅从react 挂钩表单提交+也不使用RTK查询Mutations

Typescript泛型类型:按其嵌套属性映射记录列表

通过按键数组拾取对象的关键点

在对象中将缺省值设置为空值

TS如何不立即将表达式转换为完全不可变?

Angular 17子路由

在另一个类型的函数中,编译器不会推断模板文字类型

使用数组作为类型中允许的键的列表

如何在React组件中指定forwardRef是可选的?

缩小对象具有某一类型的任意字段的范围

如何从一个泛型类型推断多个类型

重写返回任何

如何将对象的字符串文字属性用作同一对象中的键类型

React Context TypeScript错误:属性';firstName';在类型';iCards|iSearch';

定义一个只允许来自另一个类型的特定字符串文字的类型的最佳方式