简体   繁体   English

引导程序在Angular2中不起作用

[英]bootstrap not working in Angular2

I was trying to use some bootstrap classes in my angular2 app but something is going wrong and bootstrap is not working. 我试图在我的angular2应用程序中使用一些引导程序类,但是出了点问题,引导程序不起作用。 I have installed bootstrap using the below command. 我已经使用以下命令安装了引导程序。

npm install bootstrap@4.0.0-alpha.6 --save

Then i have included the bootstrap.min.css and bootstrap.min.js in index.html. 然后,我在index.html中包含了bootstrap.min.css和bootstrap.min.js。

<link rel="stylesheet" href="../node_modules/bootstrap/dist/css/bootstrap.min.css">

<script src="../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>

Do I need to do any more configuration to make the bootstrap work. 我是否需要做更多配置才能使引导程序正常工作。

Below panel and classes are not working. 下面的面板和类不起作用。

    <div class="panel panel-primary">
  <div class="panel-heading">
    Register
  </div>
  <div class="panel-body">
    <form (ngSubmit) = "save()" [formGroup]="userForm">
      <fieldset>
        <div class="form-group">
          <label class="col-md-2 control-label" for="firstNameId">First Name</label>
          <div class="col-md-8">
            <input class="form-control"
                  id="firstNameId" 
                  type="text" 
                  placeholder="First Name (required)" 
                  formControlName="firstName">
          </div>  
        </div>
        <div class="form-group">
          <label class="col-md-2 control-label" for="lastNameId">Last Name</label>
          <div class="col-md-8">
            <input class="form-control"
                  id="lastNameId" 
                  type="text" 
                  placeholder="last Name (required)" 
                  formControlName="lastName">
          </div>  
        </div>
        <div class="form-group">
          <div class="col-md-4 col-md-offset-2">
            <span>
              <button class="btn btn-primary" type="submit" [disabled]="!userForm.valid">Save</button>
            </span>
          </div>
        </div>
      </fieldset>
    </form>
  </div>
</div>

The way to reference a CSS file (Bootstrap or other) depends on which module loader you're using. 引用CSS文件(Bootstrap或其他文件)的方式取决于您所使用的模块加载器。

SystemJS. SystemJS。 Your code should be working, provided the path to Boostrap is correct (in your <link href=""> tag). 只要Boostrap的路径正确(在您的<link href="">标记中),您的代码就可以正常工作。

Webpack. Webpack。 With webpack, you can import CSS files using the same syntax you import JavaScript files, ie import 'path/to/my/styles.css' (this is assuming you're coding in TypeScript, not ES5). 使用webpack,您可以使用与导入JavaScript文件相同的语法来导入CSS文件,即, import 'path/to/my/styles.css' (这是假设您使用TypeScript而不是ES5进行编码)。

Your panel class will not work in bootstrap 4. They are replaced with cards. 您的小组课程无法在引导程序4中使用。它们已替换为卡片。 http://v4-alpha.getbootstrap.com/components/card/ http://v4-alpha.getbootstrap.com/components/card/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM