Angular2(step1) 开发前准备

环境搭建&开发前准备

Node

Node.js中文网

安装  Node.js,用到其包管理工具:npm 

// 查看镜像 
npm config list
// 修改镜像
npm config set registry https://registry.npm.taobao.org 

angular-cli

  • 安装脚 手架工具:angular-cli
npm install -g @angular/cli

cli 工具的使用

angular/cli github地址

新建工程

ng new PROJECT-NAME

新建模块

// Module 模块
ng g module my-module
// 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

ES6简单语法介绍

ECMAScript 6 入门

this

箭头函数 =>

为什么叫Arrow Function?因为它的定义用的就是一个箭头:

x => x * x

上面的箭头函数相当于:

function (x) {
    return x * x;
}

箭头函数相当于匿名函数,并且简化了函数定义。箭头函数有两种格式,一种像上面的,只包含一个表达式,连{ … }和return都省略掉了。还有一种可以包含多条语句,这时候就不能省略{ ... }return

x => {
    if (x > 0) {
        return x * x;
    }
    else {
        return - x * x;
    }
}

如果参数不是一个,就需要用括号()括起来:

// 两个参数:
(x, y) => x * x + y * y

// 无参数:
() => 3.14

// 可变参数:
(x, y, ...rest) => {
    var i, sum = x + y;
    for (i=0; i<rest.length; i++) {
        sum += rest[i];
    }
    return sum;
}

如果要返回一个对象,就要注意,如果是单表达式,这么写的话会报错:

// SyntaxError:
x => { foo: x }

因为和函数体的{ … }有语法冲突,所以要改为:

// ok:
x => ({ foo: x })

TypeScript

TypeScript官网

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Chapter 1, Introducing Angular, is an introduction to Angular as well as the concepts behind it. It also covers what it takes to start writing an Angular application. Chapter 2, Hello Angular, walks through creating a very simple Angular application, and diving into how the pieces work together. It also introduces the Angular CLI. Chapter 3, Useful Built-In Angular Directives, digs into the basic built-in Angular directives (including ngFor, ngIf, etc.) and when and how to use them. Chapter 4, Understanding and Using Angular Components, covers Angular components in more detail, as well as the various options available when creating them. It also covers the basic lifecycle hooks available with components. Chapter 5, Testing Angular Components, introduces how to unit test angular components using Karma and Jasmine, along with the Angular testing framework. Chapter 6, Working with Template-Driven Forms, covers creating and working with forms in Angular, specifically template-driven forms. Chapter 7, Working with Reactive Forms, covers the other way of defining and working with forms, which is how to create and develop reactive forms. Chapter 8, Angular Services, covers Angular services, which includes how to use built-in Angular services, as well as how and when to define our own Angular services. Chapter 9, Making HTTP Calls in Angular, moves into the server communication aspect of Angular, and delves into making HTTP calls, as well as some advanced topics like interceptors and the like. Chapter 10, Unit Testing Services, takes a step back and covers unit testing again, but this time with a focus on unit testing services. This includes testing simple services and slightly harder cases like asynchronous flows as well as services and components that make HTTP calls. Chapter 11, Routing in Angular, goes in depth into how we can accomplish routing in an Angular application and covers the Angular routing module in detail as well as a majority of its features. Chapter 12, P

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值