首页 > 其他 > 详细

Angular

时间:2018-10-31 23:06:50      阅读:163      评论:0      收藏:0      [点我收藏+]

1. git clone

git clone https://github.com/angular/quickstart ng4-quickstart

2. 双向绑定:

前端:<input type="text" ng-model="name"> <h1>Hello {{name}} {{address.city}}</h1>

后端:export class AppComponent {name = ‘Hello‘; address = {province: ‘江苏‘, city: ‘苏州‘}} //address是对象

利用Angular内置json管道显示对象信息:<p>{{address | json}}</p>

3. 表单

<form (submit)="addSkill(skill.value)">

  <label>添加剂能</label>

  <input type="text" #skill>

</form>

4. 事件绑定

<button (click)="toggleSkills()">

  {{showSkill ? "隐藏技能" : "显示技能"}}

</button>

toggleSkills() {this.showSkill = !this.showSkill;}

5. *ngIf *ngFor

<div *ngIf = "members">

  <li *ngFor = "let member of members;" >

  </li>

</div>

6. HTTP

this.http.get(‘https://api.github.com...‘)

  .map(res => res.json())

  .subscribe(data => {

    if(data) this.members = data;

  });

7. 注入

export class MemberService{

  getMembers(){

    return this.http.get(‘https://api...‘).map(res => res.json())

  }

}

this.memberservice.getMembers()

  .subscribe(data => {

    if(data) this.members = data;

  });

 

Angular

原文:https://www.cnblogs.com/embeddedking/p/9886383.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!