zoukankan      html  css  js  c++  java
  • [Angular 2] Create Angular 2 Porject with Angular CLI

    Install:

    npm i -g angular-cli

    Create a project:

    ng new hello-angular2

    Run the project:

    cd hello-angular2
    ng serve

    Change the port:

    ng serve --port 4201 --live-reload-port 49153

    Create a component:

    ng g component contact-list-component

    The component will be created in src/app/contact-list-component.

    // app.component.ts
    
    import { Component } from '@angular/core';
    import {ContactListComponentComponent} from "./contact-list-component/contact-list-component.component";
    
    @Component({
      moduleId: module.id,
      selector: 'app-root',
      templateUrl: 'app.component.html',
      styleUrls: ['app.component.css'],
      directives: [ContactListComponentComponent]
    })
    export class AppComponent {
      title = 'app works!';
    }

    Generate a child component:

    The child component should live inside parent component, for example, we create a contact-detail-component:

    cd ./contact-list-component
    ng g component ./contact-detail-component
    //contact-iist-component.ts
    
    import { Component, OnInit } from '@angular/core';
    import {ContactDetailComponentComponent} from "./contact-detail-component/contact-detail-component.component";
    
    @Component({
      moduleId: module.id,
      directives: [ContactDetailComponentComponent],
      selector: 'app-contact-list-component',
      templateUrl: 'contact-list-component.component.html',
      styleUrls: ['contact-list-component.component.css']
    })
    export class ContactListComponentComponent implements OnInit {
    
      constructor() {}
    
      ngOnInit() {
      }
    
    }

    If everything went well, you should see:

  • 相关阅读:
    angular 路由请求js文件
    WeX5的简单介绍及UI的简单讲解
    JAVA 反射
    JAVA 线程
    JAVA 远程通讯机制
    用Java实现几种常见的排序算法
    自动完成
    Springmvc和poi3.9导出excel并弹出下载框
    Windows Server 搭建企业无线认证(NPS搭建)
    Windows Server 搭建企业无线认证(Radius认证方案)
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5686865.html
Copyright © 2011-2022 走看看