UFO ET IT

이름이 'recipient'인 양식 컨트롤에 대한 값 접근자가 없습니다.

ufoet 2020. 12. 3. 21:09
반응형

이름이 'recipient'인 양식 컨트롤에 대한 값 접근자가 없습니다.


Angular 2 Rc.5로 업그레이드 한 후이 오류가 발생했습니다. 이것은 내 구성 요소 템플릿입니다.

<md-input
    [(ngModel)]="recipient"
    name="recipient"
    placeholder="Name"
    class="col-sm-4"
    (blur)="addRecipient(recipient)">
</md-input>

내 app.module.ts는 FormsModule

나는 또한 private recipient;내 구성 요소에서 선언하려고했습니다 .

내가 뭔가를 놓치고 있습니까? 이 오류가 발생하는 이유는 무엇입니까?

No value accessor for form control with name: 'recipient'

다음과 같이 입력에 ngDefaultControl 속성을 추가해야합니다.

<md-input
    [(ngModel)]="recipient"
    name="recipient"
    placeholder="Name"
    class="col-sm-4"
    (blur)="addRecipient(recipient)"
    ngDefaultControl>
</md-input>

이 게시물의 댓글에서 발췌 :

angular2 rc.5 사용자 지정 입력, 이름이 지정되지 않은 양식 컨트롤에 대한 값 접근 자 없음

참고 : @ angular / material의 이후 버전의 경우 :

요즘에는 다음과 같이 작성해야합니다.

<md-input-container>
    <input
        mdInput
        [(ngModel)]="recipient"
        name="recipient"
        placeholder="Name"
        (blur)="addRecipient(recipient)">
</md-input-container>

참조 https://material.angular.io/components/input/overview를


FormsModule에 속하지 않는 md-input을 사용하고 있으므로 MaterialModule도 가져와야합니다.

참고 URL : https://stackoverflow.com/questions/38978166/no-value-accessor-for-form-control-with-name-recipient

반응형