我如何访问注入到我的组件中的 formControl?

How can i access to my formControl which is injected in my component?

我有父组件。在里面我正在投射一个输入。

<app-form-field>
  <input #input [id]="autoCompleteSearchInput" type="text" autoComplete="off"
   class='input-underline search-bar idented-text' [placeholder]="placeholder" 
   [formControl]="search" />
</app-form-field>

所以我有这个控制权

[formControl]="search"

现在我找不到一种方法来访问从我的 AppFormFieldComponent 注入的内容。

我试过 HTML

   <ng-content select=".input-underline"></ng-content>

TS

 @ContentChild(FormControlName, {static: false}) formControl: FormControlName;

ngAfterContentInit() {
  console.log(this.formControl);
}

但它给了我未定义的。

我怎样才能访问这个表单控件,这样我才能知道我的组件输入的内容是什么?

您正在使用 [formControl],因此您应该在 @ContentChild:

中使用 FormControlDirective
@ContentChild(FormControlDirective, {static: false})
formControl?: FormControlDirective;

ngAfterContentInit() {
  console.log(this.formControl);
}