首页 > 解决方案 > 无法使用界面用户读取未定义角度 wite 的属性“知道”

问题描述

我正在使用角度服务从我的服务器获取数据,这是我的用户服务代码。

GetUser(id: any): Observable<User>
{
  const header = new HttpHeaders();
  header.append('content-type', 'application/json');
  return this.httpclient.get<User>(this.baseurl + '/' + id, {headers: header});
}

模型用户

export interface User {
    id: number;
    username: string;
    knowas: string;
    age: number;
    gender: string;
    created: Date;
    lastActive: Date;
    photourl: string;
    city: string;
    country: string;
    introduction?: string;
    lookingFor?: string;
    photos?: Photo[];
}

我使用我的 memberdetialcomponent.ts 中的代码和我的代码。

export class MemberDetialComponent implements OnInit {
user: User;
id: number;
  constructor(private userservice: UserService, private alertify: AlertifyService, private route: ActivatedRoute) { }

  ngOnInit() {
    this.loaduser();
    console.log(this.user);
  }
  // tslint:disable-next-line: typedef
  loaduser()
  {
    this.userservice.GetUser(+this.route.snapshot.params['id']).subscribe(
      (users: User) =>
      {
        this.user = users;
       // console.log(this.user);
      }, ( error) =>
      {
       this.alertify.error(error);
      }
    );
  }
}

当使用 console.log(this.user); 我得到了信息,但在我的 html 中使用它说无法读取您的财产知道。这是我的 html 代码

<h6>
  {{user.knowas}}
</h6>

有人可以帮我解决这个问题吗?谢谢

标签: jsonangularjs

解决方案


推荐阅读