如何根据环境属性将子组件绑定到父组件?

时间:2019-01-03 16:11:56

标签: angular

我正在尝试基于if语句表单环境文件将子组件绑定到父组件中:

parent.component.html

<form>
   ...
   <app-address *ngIf="userAddress"... #inputUserAddress></app-child>
   ...
   <button (click)="addUserAttribute( inputUserAddress.value )"></button>
</form>

parent.component.ts

public userAddress = environment.formFields.address;

environment.prod.ts

formFields{ address: true}

当我运行ng serve --prod时,子组件似乎尚未绑定到父组件。错误:

  

类型“ ElementRef”上不存在属性“值”

如果我删除*ngIf并直接将其直接嵌入,那么它会直接工作。

我要去哪里错了?这种概念行得通吗?

2 个答案:

答案 0 :(得分:0)

您需要将此属性填充到您的environment.prod.ts文件中。

答案 1 :(得分:0)

您正在访问ElementRef类型。

https://angular.io/api/core/ElementRef

将HTML更改为此:

<button (click)="addUserAttribute( inputUserAddress.nativeElement.value )"></button>
相关问题