[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 --live-reload-port
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 2] Create Angular 2 Porject with Angular CLI的更多相关文章
- Angular 个人深究(一)【Angular中的Typescript 装饰器】
Angular 个人深究[Angular中的Typescript 装饰器] 最近进入一个新的前端项目,为了能够更好地了解Angular框架,想到要研究底层代码. 注:本人前端小白一枚,文章旨在记录自己 ...
- 从Java角度理解Angular之入门篇:npm, yarn, Angular CLI
本系列从Java程序员的角度,带大家理解前端Angular框架. 本文重点介绍Angular的开发.编译工具:npm, yarn, Angular CLI,它们就像Java在中的Maven,同时顺便介 ...
- (转载)从Java角度理解Angular之入门篇:npm, yarn, Angular CLI
本系列从Java程序员的角度,带大家理解前端Angular框架. 本文是入门篇.笔者认为亲自动手写代码做实验,是最有效最扎实的学习途径,而搭建开发环境是学习一门新技术最需要先学会的技能,是入门的前提. ...
- angular.module()创建、获取、注册angular中的模块
// 传递参数不止一个,代表新建模块;空数组代表该模块不依赖其他模块 var createModule = angular.module("myModule", []); // 只 ...
- [Angular 2] Create Shareable Angular 2 Components
Components that you use across multiple applications need to follow a module pattern that keeps them ...
- [Angular Directive] Create a Template Storage Service in Angular 2
You need to define a <template> to be able to use it elsewhere in your app as a TemplateRef. Y ...
- [Angular 2] Create template with Params
Angular 2 templates have a special let syntax that allows you to define and pass a context when they ...
- [Angular 2] Create a simple search Pipe
This lesson shows you how to create a component and pass its properties as it updates into a Pipe to ...
- [Angular 2] Order Dynamic Components Inside an Angular 2 ViewContainer
By default, when you generate components, they will simply be added to the page in order, one after ...
随机推荐
- 第八章CDC设备
8.1 CDC设备介绍 USB的CDC类是USB通信设备类(Communication Device Class)的简称.CDC类是USB组织定义的一类专门给各种通信设备(电信通信设备和中速网络通信设 ...
- .htaccess文件的详解以及404页面的设置
打开记事本,写入以下代码: ErrorDocument 404 /404.html保存成.htaccess文件上传到网站的根目录. /404.html是目录名和文件名,可以改成自己的名字.QUOTE: ...
- NIS 服务器
有没有想过,如果我有十部 Linux 主机,这十部主机仅负责不同的功能,事实上, 所有的主机账号与对应的密码都相同!那么我是将账号与密码分别设定置在十部计算机上面, 还是可以透过一部主机做为账号管理的 ...
- The Little Redis Book
一.概念简介: Redis: Redis是一款开源的Key-Value数据库,运行在内存中,由ANSI C编写,详细的信息在Redis官网上面有,因为我自己通过google等各种渠道去学习Redis, ...
- 白书P60 - 硬币问题
白书P60 - 硬币问题 完全背包.DP #include <iostream> #include <cstdio> #include <cstring> usin ...
- ORACLE RAC NTP 时间服务器配置
Linux 时间同步配置 . 一. 使用ntpdate 命令 1.1 服务器可链接外网时 # crontab -e 加入一行: */1 * * * * ntpdate 210.72.145.44 21 ...
- jquery 创建 SVG DOM 的处理方法
使用的是 createElement 方法 这个是无法生成SVG DOM的 可以使用下方的方法生成 var svgns = "http://www.w3.org/2000/svg" ...
- (转载)SQL Server 2005 日志文件过大处理
由于安装的时候没有计划好空间,默认装在系统盘,而且又没有做自动备份.截断事务日志等,很快LDF文件就达到十几G,或者几十G ,此时就不得不处理了. 备份和计划就不说了,现在就说下怎么把它先删除吧: 1 ...
- MySql配置参数很全的Mysql配置参数说明
MySql配置参数 很全的Mysql配置参数说明 1. back_log 指定MySQL可能的连接数量.当MySQL主线程在很短的时间内得到非常多的连接请求,该参数就起作用,之后主线程花些时间(尽管很 ...
- POJ 2502 Subway dij
这个题的输入输出注意一下就好 #include<cstdio> #include<cstring> #include<queue> #include<cstd ...