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
- GET
GetCfgList() {
this.http.get<string>(this.url).subscribe(ret=>{
console.log(ret)
})
}
- POST
<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)
})
}