编辑功能错误

时间:2018-04-18 12:19:21

标签: angular spring-boot

我试图获取有关我想在表单中编辑的用户的数据,但它让我得到关于获取这些数据的同一行的错误:**** this.user = data

这是:edit-user.component.ts:

CREATE TRIGGER Insert_Award_list_INTO_AWARDStesting2
ON MasterEntries
AFTER INSERT
AS
    DECLARE @rankedcount INT

    SELECT @rankedcount = Count(CompetitiveEventCode)
    FROM MasterEntries
    WHERE CompetitiveEventCode = 'AGPRO' 
      AND Ranked = 1 AND Ranked = 2 And Ranked = 3;

    IF @rankedcount = 6
    BEGIN
        INSERT INTO AwardList(CompetitiveEventName, CategoryDescription, FirstName, LastName, ParishName,
                              Region, Institution, AverageMark, Ranked, AwardPlacing)
            SELECT  
                me.CompetitiveEventName,me.CategoryDescription, me.FirstName, me.LastName, me.ParishName, 
                me.Region, me.Institution, me.AverageMark, me.Ranked, me.AwardPlacing 
            FROM 
                MasterEntries me
            LEFT JOIN
                AwardList al ON me.Institution = al.Institution
    END
在users.component.ts中的

我做了与按钮相关的功能:

 import { Component, OnInit } from '@angular/core';
 import {User} from '../../model/model.user';
 import {ActivatedRoute, Router} from '@angular/router';
 import {UsersService} from '../../services/users.service';

 @Component({
 selector: 'app-edit-user',
 templateUrl: './edit-user.component.html',
 styleUrls: ['./edit-user.component.css']
  })
export class EditUserComponent implements OnInit {
 mode = 1 ;
 user: User = new User ();
 idUser: number ;

 constructor(public activatedRoute: ActivatedRoute , public userservice: 
 UsersService , public router: Router) {
this.idUser = activatedRoute.snapshot.params['id'] ;
 }

 ngOnInit() {
 this.userservice.getUser(this.idUser)
  .subscribe(data => {
 this.user = data ;
 } , err => {
    console.log(err) ;
  }) ;
  }

 updateUser () {
 this.userservice.updateUser(this.user)
 .subscribe(data => {
  console.log(data) ;
  alert('User updated !') ;
  this.router.navigate(['users']) ;
  } , err => {
console.log(err);
alert('Error') ;
 }) ;
 }

 }
在user.service.ts中的

我做了这两个:

   onEditUser (id: number) {
   this.router.navigate(['editUser', id]);
    }

但是我告诉了你关于this.user = data

的信息
    getUser(id: number) {
    return this.http.get('http://localhost:8081/users/' + id);
    }
     updateUser(user: User) {
     return this.http.put('http://localhost:8081/users/' + user.id , user);
   }

2 个答案:

答案 0 :(得分:0)

当您订阅htt.get('url');时,它将返回响应对象。所以你需要在传递给EditUserComponent之前解析它。

从服务中的RxJS导入地图运算符,如import 'rxjs/add/operator/map';

然后编辑下面的getUser方法

    getUser(id: number) {
        return this.http.get('http://localhost:8081/users/' + id)
            .map(response => response.json());
    }

希望这能解决您的问题!快乐编码:)

答案 1 :(得分:0)

尝试

user: any={};

而不是

 user: User = new User ();