Angular2:直接绑定

时间:2016-12-16 11:10:19

标签: angular

我创建了一个具有属性的组件,该属性在ngOnInit上初始化:

@Component({
  //...
})
export class Validate implements OnInit, OnDestroy {

  private user: UserDTO;

  constructor(private router: Router, private route: ActivatedRoute, private userService: UsersService) {}

  ngOnInit():void {
    this.sub = this.route.queryParams.subscribe(params => {
      if (this.id != undefined && this.token != undefined)
        this.userService.get("id")
        .subscribe(
          (result: UserDTO) => {
            this.user = result;
          }
        )
      else
        this.router.navigate(['/error']);
    });
  }
  //...
}

UserDTO.ts:

export interface UserDTO {
    id?: string;
    username?: string;
    cname?: string;
    sname?: string;
    mail?: string;
}

在我的模板上,我写的user.cname显示在标记内:

<header>
  <h3>Hi {{user.cname}}!!!</h3>
</header>

尽管如此,<h3> tag内没有显示任何内容。

有什么想法吗?

0 个答案:

没有答案