angular 前端框架ngx-admin简单纪要

2019-04-22  本文已影响0人  蔡得不敢吱声

URL传参

页面:

 <a [routerLink]="['/hero', hero.id]">

路由

{ path: 'hero/:id',      component: HeroDetailComponent } 

接收:

  constructor(private route: ActivatedRoute) {}
  this.route.snapshot.paramMap.get('id');

参考:https://angular.io/guide/router

POST & GET

GetCfgList() {
    this.http.get<string>(this.url).subscribe(ret=>{
          console.log(ret) 
    })
}
 <textarea name="content" [(ngModel)]="content"></textarea>  //注意这里要加“name” 不然报错
 <button (click)="writeDetailData(content)" class="btn btn-success">确认</button>

    writeDetailData(content:string) {
        let id = this.route.snapshot.paramMap.get("id")
        let body = {"id":id, "content":content}
        this.http.post<string>(this.url,body).subscribe(ret=>{
            console.log(ret)
        })
    }
上一篇下一篇

猜你喜欢

热点阅读