首页 > 其他 > 详细

点击编辑,进入编辑页面并把值渲染到页面上

时间:2018-01-23 00:00:06      阅读:268      评论:0      收藏:0      [点我收藏+]

1.

//服务中
//获取测验列表
    getListData(): Promise<FormData[]>{
        console.log(this.listUrl)
       return this.http.get(this.listUrl)
       .toPromise()
       .then(response => {
            console.log(response.json().data)
           return response.json().data as FormData[];
            
       })
       .catch(this.handleError)
    }

    //获取单个测验信息
    getTest(id: number): Promise<FormData> {
        return this.getListData()
                   .then(test => test.find(data => data.id == id));
                  
      }

2.编辑页面中

  ngOnInit(): void {
    this.route.paramMap
      .switchMap((params: ParamMap) =>{
          return this.dataService.getTest(+params.get(‘id‘))
      }).subscribe((data)=>{
        this.item = data;
      });
  }

3.引入

import { ActivatedRoute, ParamMap } from ‘@angular/router‘;

// 构造
  constructor(
    private dataService: DataService,
    private route: ActivatedRoute,
    private location: Location,
  ) {
 
  }

 

点击编辑,进入编辑页面并把值渲染到页面上

原文:https://www.cnblogs.com/linsx/p/8331649.html

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