---
title: "Discussion on \"Creating custom form controls using Control Value Accessor in Angular\" | Hashnode"
description: "Discussion on \"Creating custom form controls using Control Value Accessor in Angular\". How to create custom form controls in Angular using ControlValueAccessor? We can create custom form components and connect them to either template-driven forms or reactive forms.\nSo when I say custom form controls, I am talking about those elements t..."
url: "https://hashnode.com/posts/custom-form-controls-controlvalueaccessor-in-angular/60ec556a573c235ee639cbf9"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Creating custom form controls using Control Value Accessor in Angular](https://sreyaj.dev/custom-form-controls-controlvalueaccessor-in-angular?utm_source=hashnode&utm_medium=feed)

How to create custom form controls in Angular using ControlValueAccessor? We can create custom form components and connect them to either template-driven forms or reactive forms. So when I say custom form controls, I am talking about those elements t...

Jul 12, 2021 · 9 min read · sreyaj.dev  
Updated Dec 14, 2021  
Read the article

-   [#angularjs](https://hashnode.com/tag/angularjs)
-   [#angular-2](https://hashnode.com/tag/angular-2)
-   [#javascript](https://hashnode.com/tag/javascript)
-   [#typescript](https://hashnode.com/tag/typescript)
-   [#web-development](https://hashnode.com/tag/web-development)

## Written by

[Adithya Sreyaj](https://hashnode.com/@adisreyaj)

@adisreyaj · Kerala, IN

  
[View profile](https://hashnode.com/@adisreyaj)

Full stack dev ✨

Full stack web developer with main focus in Angular and NodeJs. Loves creating blogs, a side projects when I can find time.

## Responses 3

Markdown supported · ⌘↵ to post

[Joe Smith](https://hashnode.com/@averageGuy)

[Aug 1, 2024](https://hashnode.com/posts/custom-form-controls-controlvalueaccessor-in-angular/60ec556a573c235ee639cbf9/comment/66ab8ae9c1914e18cf47bcd0)

Hi. Great article. i was just wondering for the following " this.onTouched(); // <-- mark as touched this.selected = code; this.onChanged(code); // <-- call function to let know of a change "

why does calling this.onTouched(); mark it as touched. is it not an empty function?

[Adithya Sreyaj](https://hashnode.com/@adisreyaj)

[Aug 1, 2024](https://hashnode.com/posts/custom-form-controls-controlvalueaccessor-in-angular/60ec556a573c235ee639cbf9/comment/66ab8ae9c1914e18cf47bcd0#reply-66abc3a1ef85411abe8e0014)

Angular actually gives you a reference to function in the `registerOnTouched()` callback. That function is wired up internally by Angular such that If we call the function, Angular will mark the form control as touched.

Ref: [v17.angular.io/api/forms/ControlValueAccessor](https://v17.angular.io/api/forms/ControlValueAccessor#registerontouched)

[Joe Smith](https://hashnode.com/@averageGuy)

[Aug 2, 2024](https://hashnode.com/posts/custom-form-controls-controlvalueaccessor-in-angular/60ec556a573c235ee639cbf9/comment/66ab8ae9c1914e18cf47bcd0#reply-66ac289cf1a2d34782cdb6ef)

[Adithya Sreyaj](https://hashnode.com/@adisreyaj) Thanks.

[Balaji Balamurugan](https://hashnode.com/@BalajiBalamurugan)

[Dec 1, 2021](https://hashnode.com/posts/custom-form-controls-controlvalueaccessor-in-angular/60ec556a573c235ee639cbf9/comment/61a7253dbe456923c52bb3f7)

what about validation in cva ? how can we do that ?

[Adithya Sreyaj](https://hashnode.com/@adisreyaj)

[Dec 1, 2021](https://hashnode.com/posts/custom-form-controls-controlvalueaccessor-in-angular/60ec556a573c235ee639cbf9/comment/61a7253dbe456923c52bb3f7#reply-61a77b85be456923c52bbb05)

We can use `NG_VALIDATORS` for adding validations to the custom element. I will try to write an article about the same.

[Rob Levin](https://hashnode.com/@agnosticui-guy)

[Sep 30, 2021](https://hashnode.com/posts/custom-form-controls-controlvalueaccessor-in-angular/60ec556a573c235ee639cbf9/comment/61561c67e896275f335dfd1f)

Really helpful tutorial Adithya. I gotta write one of these at work today and your tut very easy to understand!

[Adithya Sreyaj](https://hashnode.com/@adisreyaj)

[Oct 4, 2021](https://hashnode.com/posts/custom-form-controls-controlvalueaccessor-in-angular/60ec556a573c235ee639cbf9/comment/61561c67e896275f335dfd1f#reply-615afc84ad6beb6f6506edf8)

Glad it was helpful ❤️
