无法将数据绑定添加到Angular 6组件

时间:2018-08-12 11:21:57

标签: angular visual-studio typescript

我有一个component.ts文件,如下所示:

@Component({
  selector: 'app-room-details-detail',    
  templateUrl: './room-details-detail.component.html',    
  styleUrls: ['./room-details-detail.component.css']
})

export class RoomDetailsDetailComponent implements OnInit {    
  private roomDetails = {};    
  private test = "Hello";

  constructor(private roomDetailsService: RoomDetailsService) { }

  ngOnInit() {   
    this.getRoomDetails();
  }

  public getRoomDetails() {    
    this.roomDetailsService.getRoomDetails().subscribe(data => {
      this.roomDetails = data;
      console.log(data);
    });
  }
}

数据如下:{"floorArea":15.65333333,"volume":56.546333333,"paintRequired":9.768542}

当我添加时:<li>{{roomDetails.floorArea}}</li><li>{{test}}</li> 到我的component.html文件时,在构建时出现此错误:

命令ng build --aot以代码1退出。

我正在使用Visual Studio 15.7.6

1 个答案:

答案 0 :(得分:0)

@JB Nizet,感谢您提供有关使用ng build --aot的技巧。这样就解决了:

public roomDetails = {};更改为public roomDetails;