ng-book 2 r60 (Angular 4) 简介

来源:互联网 发布:单片机助手 编辑:程序博客网 时间:2024/06/06 06:46

Based on ng-book 2 r60 version, personal notes
基于 Angular 权威教程 r60版本 , 个人笔记

  • Angular CLI
    • start a new project
    • 默认端口
    • 新建组件
    • 更新
  • Angular版本
  • Overall

Angular CLI

不是必须,只是一个快速构建工具
not a requirement, simply a wrapper around Webpack.
install
npm install -g @angular/cli
usage
ng -help

start a new project

ng new XXcd xxng service

默认端口

http://localhost:4200/
configure host
ng serve --host 0.0.0.0 --port 4201

新建组件

ng generate or ng g

Scaffold Usage Component ng g component my-new-component Directive ng g directive my-new-directive Pipe ng g pipe my-new-pipe Service ng g service my-new-service Class ng g class my-new-class Guard ng g guard my-new-guard Interface ng g interface my-new-interface Enum ng g enum my-new-enum Module ng g module my-module

angular-cli will add reference to components, directives and pipes automatically in the app.module.ts. If you need to add this references to another custom module, follow this steps:

  1. ng g module new-module to create a new module
  2. call ng g component new-module/new-component

This should add the new component, directive or pipe reference to the new-module you’ve created.

更新

同时需要global and local
Global package:

npm uninstall -g @angular/clinpm cache cleannpm install -g @angular/cli@latest

Local project package:

rm -rf node_modules dist # use rmdir /S/Q node_modules dist in Windows Command Prompt; use rm -r -fo node_modules,dist in Windows PowerShellnpm install --save-dev @angular/cli@latestnpm install

Angular版本

最早是叫AngularJS, 官方声明中,AngularJS指的是Angjular 1.x 版本。 后面的版本 Angular用了TypeScript替代JavaScript, 后缀JS去掉了,也被称为 Angular 2。
在2017年,Anjular团队用语义版本名称,也就是不再叫做Anjular X, 而只是Anjular。 没有数字。目前(2017)最新版本俗称Angjular 4。
Anjular 的JS版本也就是1.x版本,被指定为AnjularJS。后续版本目前(2017)就叫做Anjular。两个版本是两个不同的项目。

Overall

本书可以分为几个部分:
基础部分,创建第一个app, 使用内置组件并且学会创建组件。
中间部分,使用表格,APIs, 路由, 和依赖注入(Dependency Injection)
进阶部分,数据结构,管理client和server的state,两种方法:RxJS Observables 和Redux。
最终部分,学习写出复杂的组件,写出tests,如何从Anjular 1.x 升级到Anjular 4.0+,学习使用NativeScript写出原生移动apps
本书目的:学习如何打造一个实战Anjular项目,节省了在不同博客,教程之间查阅时间。