美文网首页前端你不进来看看?
2018-12-10创建基础组件

2018-12-10创建基础组件

作者: HarryPang | 来源:发表于2018-12-10 18:06 被阅读0次

    1. 使用angular cli创建组件

    ng g component navbar
    ng g component stars
    ng g component product
    ng g component search
    ng g component carousel
    ng g component footer
    

    都能看到如下这样,就是生成成功了

    CREATE src/app/stars/stars.component.html (24 bytes)
    CREATE src/app/stars/stars.component.spec.ts (621 bytes)
    CREATE src/app/stars/stars.component.ts (265 bytes)
    CREATE src/app/stars/stars.component.css (0 bytes)
    UPDATE src/app/app.module.ts (1251 bytes)
    

    2. 在app.component.html中构建基础布局框架

    <app-navbar></app-navbar>
    <div class="container">
      <div class="row">
        <div class="col-md-3">
          <app-search></app-search>
        </div>
        <div class="col-md-9">
          <div class="row">
              <app-carousel></app-carousel>
          </div>
          <div class="row">
              <app-product></app-product>
          </div>
        </div>
      </div>
    </div>
    <app-footer></app-footer>
    <router-outlet></router-outlet>
    

    3.navbar.component.html

    <nav class="navbar navbar-expand-lg navbar-light bg-light">
        <a class="navbar-brand" href="#">在线竞拍</a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
          <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
          <ul class="navbar-nav">
            <!-- <li class="nav-item active">
              <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
            </li> -->
            <li class="nav-item">
              <a class="nav-link" href="#">关于我们</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="#">联系我们</a>
            </li>
            <li class="nav-item">
              <a class="nav-link" href="#">网站地图</a>
            </li>
          </ul>
        </div>
      </nav>
    

    4. footer.component.html

    <div class="container">
      <hr>
      <footer>
        <div class="row">
          <div class="col-md-12">
            <p>这是页脚</p>
          </div>
        </div>
      </footer>
    </div>
    

    5. search.component.html

    <form>
        <div class="form-group">
          <label for="prodcut_name">商品名称</label>
          <input type="text" class="form-control" id="prodcut_name" placeholder="商品名称">
        </div>
        <div class="form-group">
          <label for="prodcut_price">商品价格</label>
          <input type="text" class="form-control" id="prodcut_price" placeholder="商品价格">
        </div>
        <div class="form-group">
            <label for="prodcut_type">商品类别</label>
            <select class="form-control" id="prodcut_type">
              <option>1</option>
              <option>2</option>
              <option>3</option>
              <option>4</option>
              <option>5</option>
            </select>
          </div>
        <div class="form-check">
        <button type="submit" class="btn btn-primary">搜索</button>
        </div>
      </form>
    

    6. carsouel.component.html

    <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
      <ol class="carousel-indicators">
        <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
        <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
        <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
      </ol>
      <div class="carousel-inner">
        <div class="carousel-item active">
          <img class="d-block w-100" src="http://placehold.it/800x300" alt="First slide">
        </div>
        <div class="carousel-item">
          <img class="d-block w-100" src="http://placehold.it/800x300" alt="Second slide">
        </div>
        <div class="carousel-item">
          <img class="d-block w-100" src="http://placehold.it/800x300" alt="Third slide">
        </div>
      </div>
      <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
      </a>
      <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
      </a>
    </div>
    

    7. product.component.html

    <div class="col-md-4 col-sm-4 col-lg-4">
      <div class="thumbnail">
        <img src="http://placehold.it/320x150" alt="">
        <div class="caption">
          <h4 class="pull-right">xxx</h4>
          <h4><a href="#">yyy</a></h4>
          <p>zzzz</p>
        </div>
        <div>
          <app-stars></app-stars>
        </div>
      </div>
    </div>
    

    相关文章

      网友评论

        本文标题:2018-12-10创建基础组件

        本文链接:https://www.haomeiwen.com/subject/fcrdhqtx.html