Twitter bootstrap 角度4:如何包括引导?
我是一名后端开发人员,我只是在玩Angular4。所以我做了这个安装教程: 考虑到这一点,我如何才能将引导添加到应用程序中,以便使用类“container fluid”或“col-md-6”之类的东西Twitter bootstrap 角度4:如何包括引导?,twitter-bootstrap,angular,Twitter Bootstrap,Angular,我是一名后端开发人员,我只是在玩Angular4。所以我做了这个安装教程: 考虑到这一点,我如何才能将引导添加到应用程序中,以便使用类“container fluid”或“col-md-6”之类的东西 npm install --save bootstrap 然后,在angular-cli.json(在项目的根文件夹中)中,查找样式,并添加如下引导css文件: "styles": [ "../node_modules/bootstrap/dist/css/bootstrap.min.cs
npm install --save bootstrap
然后,在angular-cli.json(在项目的根文件夹中)中,查找样式
,并添加如下引导css文件:
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles.css"
],
更新:在angular 6+
angular cli.json
中更改为angular.json
在Angular4中,当您处理@types系统时,应执行以下操作:
做
tsconfig.json
查找类型数组并添加jquery和bootstrap条目
"types": [
"jquery",
"bootstrap",
"node"
]
Index.html
在标题部分添加以下条目
<link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="node_modules/jquery/dist/jquery.min.js "></script>
<script src="node_modules/bootstrap/dist/js/bootstrap.js "></script>
然后开始同时使用jquery和bootstrap。在项目中运行以下命令,即 npm安装bootstrap@4.0.0-alpha.5--保存 安装上述依赖项后,运行以下npm命令,该命令将安装引导模块npm安装--save@ng bootstrap/ng bootstrap 请检查此项以供参考- 将以下导入从'@ng bootstrap/ng bootstrap'添加到app.module import{NgbModule};并将NgbModule添加到导入中 在stye.css中 @导入“./node_模块/bootstrap/dist/css/bootstrap.min.css” 为了在angular中配置/集成/使用引导,首先我们需要安装 使用npm的引导包 安装软件包 注意:--save命令将在package.json文件中的angular应用程序中保存依赖项 现在我们已经安装了带有上述步骤的软件包,现在我们可以告诉Angular CLI 它需要使用以下任一选项或两个选项来加载这些样式: 选项1)添加到文件src/styles.css中 我们可以添加依赖项,如下所示: 选项2)添加到angular-cli.json或angular.json 我们可以将样式css文件添加到位于的angular-cli.json或angular.json文件中 angular应用程序的根文件夹,如下所示:
添加到angular-cli.json中
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles.css"
],
"scripts": [
"../node_modules/bootstrap/dist/js/bootstrap.js"
],
它会工作的,我检查过了。您可以使用cdn进行引导和jquery,或者直接在应用程序中安装bootstarp 与: 也可以使用,但这并不合适 Angular 4-引导程序/@ng引导程序设置 首先使用以下命令将引导程序安装到项目中:
npm安装--保存引导程序
然后添加此行“./node\u modules/bootstrap/dist/css/bootstrap.min.css”
到样式中的angular-cli.json文件(根文件夹)
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles.css"
],
安装上述依赖项后,通过以下方式安装ng引导程序:
npm安装--保存@ng bootstrap/ng bootstrap
安装后,您需要导入主模块
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
在此之后,您可以使用所有引导窗口小部件(例如旋转木马、模态、弹出窗口、工具提示、选项卡等)和一些附加功能(日期选择器、评级、时间选择器、提前键入)。如果您使用的是Sass/Scss,请遵循以下操作: 是否安装npm
npm install bootstrap --save
并将import
语句添加到sass/scss文件中
@import '~bootstrap/dist/css/bootstrap.css'
观看视频或按照步骤进行操作 有三种方法可以在项目中包含引导
1) 在index.html文件中添加CDN链接
2) 使用npm安装引导程序,并在angular.json中设置路径 3) 使用npm安装引导程序并在index.html文件中设置路径 我建议您使用npm安装以下两种引导方法,因为它安装在您的项目目录中,您可以轻松访问它 方法1
将Bootstrap、Jquery和popper.js CDN路径添加到您的angular project index.html文件中 Bootstrap.css
“
Bootstrap.js
“
Jquery.js
Popper.js
方法2
1) 使用npm安装引导程序
npm install bootstrap --save
在安装Bootstrap 4之后,我们需要另外两个javascript包,即Jquery和Popper.js,没有这两个包。Bootstrap不完整,因为Bootstrap 4使用的是Jquery和Popper.js包,所以我们也必须安装
2) 安装JQUERY
npm install jquery --save
3) 安装Popper.js
npm install popper.js --save
现在,引导程序安装在节点\u模块文件夹中的项目目录中
打开angular.json此文件在您的angular目录中可用打开该文件并在样式[]和脚本[]路径中添加bootstrap、jquery和popper.js文件的路径参见下面的示例
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles.css"
],
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/popper.js/dist/umd/popper.min.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js"
],
注意:不要更改js文件的序列,应该是这样的
方法3使用npm follow方法2安装引导程序在方法3中,我们只是在index.html文件中设置路径,而不是angular.json文件 bootstrap.css
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles.css">
Jquery.js
<script src="node_modules/jquery/dist/jquery.min.js"><br>
Bootstrap.js
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"><br>
Popper.js
npm install popper.js --save
<script src="node_modules/popper.js/dist/umd/popper.min.js"><br>
现在引导工作正常了正如我所见,您已经得到了很多答案,但您可以尝试使用此方法 它的最佳实践是不在angular中使用jquery,我更喜欢这种方法,即不使用依赖于jquery的bootstrap js组件来安装bootstrap
npm install ngx-bootstrap bootstrap --save
or
ng add ngx-bootstrap (Preferred)
如果您想在线使用引导,并且您的应用程序可以访问您可以添加的internet,请在angular中免费使用jquery代码
@import url('https://unpkg.com/bootstrap@3.3.7/dist/css/bootstrap.min.css');
进入您的main style.css文件。这是最简单的方法
参考:
注意。此解决方案从unpkg网站加载引导,并且需要具有internet访问权限 有关以下详细步骤和工作示例,您可以访问
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"><br>
<script src="node_modules/popper.js/dist/umd/popper.min.js"><br>
npm install ngx-bootstrap bootstrap --save
or
ng add ngx-bootstrap (Preferred)
@import url('https://unpkg.com/bootstrap@3.3.7/dist/css/bootstrap.min.css');
npm install bootstrap --save
npm install bootstrap@next --save
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles.scss"
]
@import '~bootstrap/dist/css/bootstrap.min.css';
"styles": [
"styles/bootstrap-3.3.7-dist/css/bootstrap.min.css",
"styles.scss"
],
@import './styles/bootstrap-3.3.7-dist/css/bootstrap.min.css';
npm install ngx-bootstrap --save
npm install bootstrap ngx-bootstrap --save
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
import { TooltipModule } from 'ngx-bootstrap/tooltip';
import { ModalModule } from 'ngx-bootstrap/modal';
@NgModule({
imports: [
BrowserModule,
BsDropdownModule.forRoot(),
TooltipModule.forRoot(),
ModalModule.forRoot()
],
// ...
})
export class AppBootstrapModule {}
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
import { TooltipModule } from 'ngx-bootstrap/tooltip';
import { ModalModule } from 'ngx-bootstrap/modal';
@NgModule({
imports: [
CommonModule,
BsDropdownModule.forRoot(),
TooltipModule.forRoot(),
ModalModule.forRoot()
],
exports: [BsDropdownModule, TooltipModule, ModalModule]
})
export class AppBootstrapModule {}
@NgModule({
imports: [BrowserModule, AppBootstrapModule],
// ...
})
export class AppModule {}
npm install bootstrap@4.0.0-alpha.6 jquery tether --save
npm install
"styles": [
"styles.css",
"../node_modules/bootstrap/dist/css/bootstrap.css"
],
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../node_modules/tether/dist/js/tether.js",
"../node_modules/bootstrap/dist/js/bootstrap.js"
]
"bootstrap": "^4.1.3",
"popper.js": "^1.14.5",
"jquery": "^3.3.1",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/client",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.css",
"src/styles.scss"
],
"scripts": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/popper.js/dist/umd/popper.min.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js"
]
},
npm install bootstrap --save
npm install popper.js --save
"architect": [{
...
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.min.css",
"src/styles.scss"
],
"scripts": [
"node_modules/jquery/dist/jquery.js",
"node_modules/popper.js/dist/umd/popper.min.js",
"node_modules/bootstrap/dist/js/bootstrap.min.js"
]
...
}]
"styles": [
"./node_modules/bootstrap/dist/css/bootstrap.min.css",
"src/styles.css"
],
npm install jquery --save
npm install popper.js --save
npm install bootstrap --save
"scripts": [
"node_modules/jquery/dist/jquery.slim.js",
"node_modules/popper.js/dist/umd/popper.js",
"node_modules/bootstrap/dist/js/bootstrap.js"
],
"styles": [
"node_modules/bootstrap/dist/css/bootstrap.css",
"src/styles.css"
],`