Angular2 学习笔记

Angular程序架构:

  • 组件:
    component组成
    装饰器:@component,
    模板:,
    控制器:
  • 服务
  • 指令
  • 模块

    开发流程:

  • 环境配置:
    用npm安装typescript和typings:
    npm install -g typescript typings(或者直接用vscode)
    安装angular-cli :
    npm install -g angular-cli

  • 创建项目:
    ng new webapp(文件名)
    ng g component name(组件名)
    ng serve(启动服务)

  • 组件中创建数组:
    1.初始化数据类型:
    export class a {
    constructor(
    public name:number/string/boolean
    ){}
    }
    2.组件中声明数组:
    private as : Array< a > ;
    3.在ngOnInit中给数组赋值:
    this.as = [
    new a(“姓名”),
    ]

  • 路由守卫

    • CanActivate(处理导航到某路由的情况)
    • CanDeactivate(处理离开路由的情况)
    • Resolve(路由激活前获取数据)
      1.创建guard目录及guard.ts文件
      2.声名:
      export class guard implements CanActivate {
      canActivate(){

           }  /通过该方法返回的值判断是否通过/
      

      }

猜你喜欢

转载自blog.csdn.net/jyliyue/article/details/68947303