Angular 6在构建生产期间出现对象错误

时间:2018-06-22 10:12:09

标签: build angular6

我在开发中有一个可以正常工作的角度应用程序,它工作正常,但是每当我尝试建立生产站点时,都会出现此错误:

 ERROR in src/app/agriculture/agriculture.component.html(20,61): : Property 'districts' does not exist on type '{}'.
src/app/agriculture/agriculture.component.html(27,60): : Property 'years' does not exist on type '{}'.
src/app/agriculture/agriculture.component.html(35,64): : Property 'view' does not exist on type '{}'.
src/app/agriculture/agriculture.component.html(41,64): : Property 'rain_fall_type' does not exist on type '{}'.
src/app/agriculture/agriculture.component.html(48,68): : Property 'Comparison' does not exist on type '{}'.
src/app/agriculture/agriculture.component.html(20,61): : Property 'districts' does not exist on type '{}'.
src/app/agriculture/agriculture.component.html(27,60): : Property 'years' does not exist on type '{}'.
src/app/agriculture/agriculture.component.html(35,64): : Property 'view' does not exist on type '{}'.
src/app/agriculture/agriculture.component.html(41,64): : Property 'rain_fall_type' does not exist on type '{}'.
src/app/agriculture/agriculture.component.html(48,68): : Property 'Comparison' does not exist on type '{}'.

我正在组件内部使用对象:

data = {};

在我的html中,我的代码是:

 <div class="col-sm-2">
      <select class='select-option' required [(ngModel)]='data.years' name="years">
       <option [ngValue]="undefined" disabled  selected> Views  </option>
       <option class='option' *ngFor='let option of views' [ngValue]="option">{{option}}</option>
      </select>
</div>

如何解决此问题以及为什么在开发模式下没有出现任何错误。

在我的组件中,我正在使用此数组进行循环:

  views = ["Graph", "Trend Line","Map View","Table"];

1 个答案:

答案 0 :(得分:0)

解决方案的问题非常简单,未定义数据对象,这就是收到此错误的原因。

我遇到了类似的问题,我犯的错误与您所做的相同。您只需将其添加到您的数据对象中即可:

 data: any = {};

这将解决您的问题。