Using FormcontrolName with label in angular 6









up vote
0
down vote

favorite












I have angular 6 project with reactive forms. I have a grid like below. Detail button, open a modal window and showing student infos. My html of dialog is like below. But it gave me No value accessor for form control with name: studentNumber error. Is my html logic is wrong?



This not working



<form [formGroup]="studentForm">
<p-dialog header="Student Detail" [(visible)]="displayStudentForm">
<div class="p-grid">
<label>Student Number</label>
<label formControlName="studentNumber"></label>
</div>
<div class="p-grid">
<label>Student Age</label>
<label formControlName="studentAge"></label>
</div>
<div class="p-grid">
<label>Student Type</label>
<label formControlName="studentType"></label>
</div>
</p-dialog>
</form>


When I tried like below, working perfectly. But, this is very long for writing everywhere.



<label>studentForm.controls.studentNumber.value</label>


When I tried like below, working perfectly



<input formControlName="studentNumber"> 


My grid










share|improve this question

























    up vote
    0
    down vote

    favorite












    I have angular 6 project with reactive forms. I have a grid like below. Detail button, open a modal window and showing student infos. My html of dialog is like below. But it gave me No value accessor for form control with name: studentNumber error. Is my html logic is wrong?



    This not working



    <form [formGroup]="studentForm">
    <p-dialog header="Student Detail" [(visible)]="displayStudentForm">
    <div class="p-grid">
    <label>Student Number</label>
    <label formControlName="studentNumber"></label>
    </div>
    <div class="p-grid">
    <label>Student Age</label>
    <label formControlName="studentAge"></label>
    </div>
    <div class="p-grid">
    <label>Student Type</label>
    <label formControlName="studentType"></label>
    </div>
    </p-dialog>
    </form>


    When I tried like below, working perfectly. But, this is very long for writing everywhere.



    <label>studentForm.controls.studentNumber.value</label>


    When I tried like below, working perfectly



    <input formControlName="studentNumber"> 


    My grid










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have angular 6 project with reactive forms. I have a grid like below. Detail button, open a modal window and showing student infos. My html of dialog is like below. But it gave me No value accessor for form control with name: studentNumber error. Is my html logic is wrong?



      This not working



      <form [formGroup]="studentForm">
      <p-dialog header="Student Detail" [(visible)]="displayStudentForm">
      <div class="p-grid">
      <label>Student Number</label>
      <label formControlName="studentNumber"></label>
      </div>
      <div class="p-grid">
      <label>Student Age</label>
      <label formControlName="studentAge"></label>
      </div>
      <div class="p-grid">
      <label>Student Type</label>
      <label formControlName="studentType"></label>
      </div>
      </p-dialog>
      </form>


      When I tried like below, working perfectly. But, this is very long for writing everywhere.



      <label>studentForm.controls.studentNumber.value</label>


      When I tried like below, working perfectly



      <input formControlName="studentNumber"> 


      My grid










      share|improve this question













      I have angular 6 project with reactive forms. I have a grid like below. Detail button, open a modal window and showing student infos. My html of dialog is like below. But it gave me No value accessor for form control with name: studentNumber error. Is my html logic is wrong?



      This not working



      <form [formGroup]="studentForm">
      <p-dialog header="Student Detail" [(visible)]="displayStudentForm">
      <div class="p-grid">
      <label>Student Number</label>
      <label formControlName="studentNumber"></label>
      </div>
      <div class="p-grid">
      <label>Student Age</label>
      <label formControlName="studentAge"></label>
      </div>
      <div class="p-grid">
      <label>Student Type</label>
      <label formControlName="studentType"></label>
      </div>
      </p-dialog>
      </form>


      When I tried like below, working perfectly. But, this is very long for writing everywhere.



      <label>studentForm.controls.studentNumber.value</label>


      When I tried like below, working perfectly



      <input formControlName="studentNumber"> 


      My grid







      angular typescript






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 12:08









      Hasan Ozdemir

      25312




      25312






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          To not repeat yourself I would create simple directive for that case:



          import Directive, HostBinding, Optional from '@angular/core';
          import ControlContainer from '@angular/forms';

          @Directive(
          selector: 'label[controlName]',
          )
          export class LabelControl
          @Input() controlName: string;

          constructor(@Optional() private parent: ControlContainer)

          @HostBinding('textContent')
          get controlValue()
          return this.parent ? this.parent.control.get(this.controlName).value : '';




          And use it as follows:



          <label controlName="studentNumber"></label>


          Ng-run Example






          share|improve this answer




















          • This is what I was looking for. Thanks @yurzui
            – Hasan Ozdemir
            Nov 11 at 12:46










          • I create your directive. But it didn't worked @yurzui. It gave me Cannot read property 'value' of null
            – Hasan Ozdemir
            Nov 11 at 13:04










          • Can you provide simple demo on stackblitz?
            – yurzui
            Nov 11 at 13:05










          • Sorry, my mistake. I did misspelling (lowerCase letter). Your code worked perfectly. Thanks again @yurzui
            – Hasan Ozdemir
            Nov 11 at 13:08






          • 1




            If we rename it to formControlName then Angular built-in directive will break your code because you will have to implement custom ControlValueAccessor. But if you want more code is executed in your application then you can definitely do this. Here's an example ng-run.com/edit/xSPCiA4IjYvLXuIQGUY6
            – yurzui
            Nov 11 at 13:24


















          up vote
          0
          down vote













          IN component, you can create a getter method which will return form control value.



          <form [formGroup]="studentForm">
          <p-dialog header="Student Detail" [(visible)]="displayStudentForm">
          <div class="p-grid">
          <label>Student Number</label>
          <label>getControlLabel('studentNumber')</label>
          </div>
          <div class="p-grid">
          <label>Student Age</label>
          <label>getControlLabel('studentAge')</label>
          </div>
          <div class="p-grid">
          <label>Student Type</label>
          <label>getControlLabel('studentType')</label>
          </div>
          </p-dialog>
          </form>


          Component:



          getControlLabel(type: string)
          return studentForm.controls[type].value;






          share|improve this answer






















          • Thanks for your reply @SureshKumarAriya. But in real scenario, there will be 30 label not 3. And foreach, I will write get method. I don't know, Is this proper and recomended way? Because, I'm looking recomended way for this?
            – Hasan Ozdemir
            Nov 11 at 12:20










          • Or should I use template driven forms for doing this @SureshKumarAriya ?
            – Hasan Ozdemir
            Nov 11 at 12:26






          • 1




            Updated the code. is it fine?
            – Suresh Kumar Ariya
            Nov 11 at 12:29






          • 1




            You can follow the first approach (i.e getter method) if we have around 10 form control labels. In your case its 30 right. Its suggessted way to call component method which will return form control value based on input value. I have used this in many places in our application and its a recommended one. Template Driven Form approach is like Angular JS approach, we won't prefer that as Angular 2+ is modern web framework.
            – Suresh Kumar Ariya
            Nov 11 at 12:36






          • 1




            Yes, you can use directive also. Its a good option
            – Suresh Kumar Ariya
            Nov 11 at 12:43










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248582%2fusing-formcontrolname-with-label-in-angular-6%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted










          To not repeat yourself I would create simple directive for that case:



          import Directive, HostBinding, Optional from '@angular/core';
          import ControlContainer from '@angular/forms';

          @Directive(
          selector: 'label[controlName]',
          )
          export class LabelControl
          @Input() controlName: string;

          constructor(@Optional() private parent: ControlContainer)

          @HostBinding('textContent')
          get controlValue()
          return this.parent ? this.parent.control.get(this.controlName).value : '';




          And use it as follows:



          <label controlName="studentNumber"></label>


          Ng-run Example






          share|improve this answer




















          • This is what I was looking for. Thanks @yurzui
            – Hasan Ozdemir
            Nov 11 at 12:46










          • I create your directive. But it didn't worked @yurzui. It gave me Cannot read property 'value' of null
            – Hasan Ozdemir
            Nov 11 at 13:04










          • Can you provide simple demo on stackblitz?
            – yurzui
            Nov 11 at 13:05










          • Sorry, my mistake. I did misspelling (lowerCase letter). Your code worked perfectly. Thanks again @yurzui
            – Hasan Ozdemir
            Nov 11 at 13:08






          • 1




            If we rename it to formControlName then Angular built-in directive will break your code because you will have to implement custom ControlValueAccessor. But if you want more code is executed in your application then you can definitely do this. Here's an example ng-run.com/edit/xSPCiA4IjYvLXuIQGUY6
            – yurzui
            Nov 11 at 13:24















          up vote
          3
          down vote



          accepted










          To not repeat yourself I would create simple directive for that case:



          import Directive, HostBinding, Optional from '@angular/core';
          import ControlContainer from '@angular/forms';

          @Directive(
          selector: 'label[controlName]',
          )
          export class LabelControl
          @Input() controlName: string;

          constructor(@Optional() private parent: ControlContainer)

          @HostBinding('textContent')
          get controlValue()
          return this.parent ? this.parent.control.get(this.controlName).value : '';




          And use it as follows:



          <label controlName="studentNumber"></label>


          Ng-run Example






          share|improve this answer




















          • This is what I was looking for. Thanks @yurzui
            – Hasan Ozdemir
            Nov 11 at 12:46










          • I create your directive. But it didn't worked @yurzui. It gave me Cannot read property 'value' of null
            – Hasan Ozdemir
            Nov 11 at 13:04










          • Can you provide simple demo on stackblitz?
            – yurzui
            Nov 11 at 13:05










          • Sorry, my mistake. I did misspelling (lowerCase letter). Your code worked perfectly. Thanks again @yurzui
            – Hasan Ozdemir
            Nov 11 at 13:08






          • 1




            If we rename it to formControlName then Angular built-in directive will break your code because you will have to implement custom ControlValueAccessor. But if you want more code is executed in your application then you can definitely do this. Here's an example ng-run.com/edit/xSPCiA4IjYvLXuIQGUY6
            – yurzui
            Nov 11 at 13:24













          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          To not repeat yourself I would create simple directive for that case:



          import Directive, HostBinding, Optional from '@angular/core';
          import ControlContainer from '@angular/forms';

          @Directive(
          selector: 'label[controlName]',
          )
          export class LabelControl
          @Input() controlName: string;

          constructor(@Optional() private parent: ControlContainer)

          @HostBinding('textContent')
          get controlValue()
          return this.parent ? this.parent.control.get(this.controlName).value : '';




          And use it as follows:



          <label controlName="studentNumber"></label>


          Ng-run Example






          share|improve this answer












          To not repeat yourself I would create simple directive for that case:



          import Directive, HostBinding, Optional from '@angular/core';
          import ControlContainer from '@angular/forms';

          @Directive(
          selector: 'label[controlName]',
          )
          export class LabelControl
          @Input() controlName: string;

          constructor(@Optional() private parent: ControlContainer)

          @HostBinding('textContent')
          get controlValue()
          return this.parent ? this.parent.control.get(this.controlName).value : '';




          And use it as follows:



          <label controlName="studentNumber"></label>


          Ng-run Example







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 12:39









          yurzui

          91.8k10180204




          91.8k10180204











          • This is what I was looking for. Thanks @yurzui
            – Hasan Ozdemir
            Nov 11 at 12:46










          • I create your directive. But it didn't worked @yurzui. It gave me Cannot read property 'value' of null
            – Hasan Ozdemir
            Nov 11 at 13:04










          • Can you provide simple demo on stackblitz?
            – yurzui
            Nov 11 at 13:05










          • Sorry, my mistake. I did misspelling (lowerCase letter). Your code worked perfectly. Thanks again @yurzui
            – Hasan Ozdemir
            Nov 11 at 13:08






          • 1




            If we rename it to formControlName then Angular built-in directive will break your code because you will have to implement custom ControlValueAccessor. But if you want more code is executed in your application then you can definitely do this. Here's an example ng-run.com/edit/xSPCiA4IjYvLXuIQGUY6
            – yurzui
            Nov 11 at 13:24

















          • This is what I was looking for. Thanks @yurzui
            – Hasan Ozdemir
            Nov 11 at 12:46










          • I create your directive. But it didn't worked @yurzui. It gave me Cannot read property 'value' of null
            – Hasan Ozdemir
            Nov 11 at 13:04










          • Can you provide simple demo on stackblitz?
            – yurzui
            Nov 11 at 13:05










          • Sorry, my mistake. I did misspelling (lowerCase letter). Your code worked perfectly. Thanks again @yurzui
            – Hasan Ozdemir
            Nov 11 at 13:08






          • 1




            If we rename it to formControlName then Angular built-in directive will break your code because you will have to implement custom ControlValueAccessor. But if you want more code is executed in your application then you can definitely do this. Here's an example ng-run.com/edit/xSPCiA4IjYvLXuIQGUY6
            – yurzui
            Nov 11 at 13:24
















          This is what I was looking for. Thanks @yurzui
          – Hasan Ozdemir
          Nov 11 at 12:46




          This is what I was looking for. Thanks @yurzui
          – Hasan Ozdemir
          Nov 11 at 12:46












          I create your directive. But it didn't worked @yurzui. It gave me Cannot read property 'value' of null
          – Hasan Ozdemir
          Nov 11 at 13:04




          I create your directive. But it didn't worked @yurzui. It gave me Cannot read property 'value' of null
          – Hasan Ozdemir
          Nov 11 at 13:04












          Can you provide simple demo on stackblitz?
          – yurzui
          Nov 11 at 13:05




          Can you provide simple demo on stackblitz?
          – yurzui
          Nov 11 at 13:05












          Sorry, my mistake. I did misspelling (lowerCase letter). Your code worked perfectly. Thanks again @yurzui
          – Hasan Ozdemir
          Nov 11 at 13:08




          Sorry, my mistake. I did misspelling (lowerCase letter). Your code worked perfectly. Thanks again @yurzui
          – Hasan Ozdemir
          Nov 11 at 13:08




          1




          1




          If we rename it to formControlName then Angular built-in directive will break your code because you will have to implement custom ControlValueAccessor. But if you want more code is executed in your application then you can definitely do this. Here's an example ng-run.com/edit/xSPCiA4IjYvLXuIQGUY6
          – yurzui
          Nov 11 at 13:24





          If we rename it to formControlName then Angular built-in directive will break your code because you will have to implement custom ControlValueAccessor. But if you want more code is executed in your application then you can definitely do this. Here's an example ng-run.com/edit/xSPCiA4IjYvLXuIQGUY6
          – yurzui
          Nov 11 at 13:24













          up vote
          0
          down vote













          IN component, you can create a getter method which will return form control value.



          <form [formGroup]="studentForm">
          <p-dialog header="Student Detail" [(visible)]="displayStudentForm">
          <div class="p-grid">
          <label>Student Number</label>
          <label>getControlLabel('studentNumber')</label>
          </div>
          <div class="p-grid">
          <label>Student Age</label>
          <label>getControlLabel('studentAge')</label>
          </div>
          <div class="p-grid">
          <label>Student Type</label>
          <label>getControlLabel('studentType')</label>
          </div>
          </p-dialog>
          </form>


          Component:



          getControlLabel(type: string)
          return studentForm.controls[type].value;






          share|improve this answer






















          • Thanks for your reply @SureshKumarAriya. But in real scenario, there will be 30 label not 3. And foreach, I will write get method. I don't know, Is this proper and recomended way? Because, I'm looking recomended way for this?
            – Hasan Ozdemir
            Nov 11 at 12:20










          • Or should I use template driven forms for doing this @SureshKumarAriya ?
            – Hasan Ozdemir
            Nov 11 at 12:26






          • 1




            Updated the code. is it fine?
            – Suresh Kumar Ariya
            Nov 11 at 12:29






          • 1




            You can follow the first approach (i.e getter method) if we have around 10 form control labels. In your case its 30 right. Its suggessted way to call component method which will return form control value based on input value. I have used this in many places in our application and its a recommended one. Template Driven Form approach is like Angular JS approach, we won't prefer that as Angular 2+ is modern web framework.
            – Suresh Kumar Ariya
            Nov 11 at 12:36






          • 1




            Yes, you can use directive also. Its a good option
            – Suresh Kumar Ariya
            Nov 11 at 12:43














          up vote
          0
          down vote













          IN component, you can create a getter method which will return form control value.



          <form [formGroup]="studentForm">
          <p-dialog header="Student Detail" [(visible)]="displayStudentForm">
          <div class="p-grid">
          <label>Student Number</label>
          <label>getControlLabel('studentNumber')</label>
          </div>
          <div class="p-grid">
          <label>Student Age</label>
          <label>getControlLabel('studentAge')</label>
          </div>
          <div class="p-grid">
          <label>Student Type</label>
          <label>getControlLabel('studentType')</label>
          </div>
          </p-dialog>
          </form>


          Component:



          getControlLabel(type: string)
          return studentForm.controls[type].value;






          share|improve this answer






















          • Thanks for your reply @SureshKumarAriya. But in real scenario, there will be 30 label not 3. And foreach, I will write get method. I don't know, Is this proper and recomended way? Because, I'm looking recomended way for this?
            – Hasan Ozdemir
            Nov 11 at 12:20










          • Or should I use template driven forms for doing this @SureshKumarAriya ?
            – Hasan Ozdemir
            Nov 11 at 12:26






          • 1




            Updated the code. is it fine?
            – Suresh Kumar Ariya
            Nov 11 at 12:29






          • 1




            You can follow the first approach (i.e getter method) if we have around 10 form control labels. In your case its 30 right. Its suggessted way to call component method which will return form control value based on input value. I have used this in many places in our application and its a recommended one. Template Driven Form approach is like Angular JS approach, we won't prefer that as Angular 2+ is modern web framework.
            – Suresh Kumar Ariya
            Nov 11 at 12:36






          • 1




            Yes, you can use directive also. Its a good option
            – Suresh Kumar Ariya
            Nov 11 at 12:43












          up vote
          0
          down vote










          up vote
          0
          down vote









          IN component, you can create a getter method which will return form control value.



          <form [formGroup]="studentForm">
          <p-dialog header="Student Detail" [(visible)]="displayStudentForm">
          <div class="p-grid">
          <label>Student Number</label>
          <label>getControlLabel('studentNumber')</label>
          </div>
          <div class="p-grid">
          <label>Student Age</label>
          <label>getControlLabel('studentAge')</label>
          </div>
          <div class="p-grid">
          <label>Student Type</label>
          <label>getControlLabel('studentType')</label>
          </div>
          </p-dialog>
          </form>


          Component:



          getControlLabel(type: string)
          return studentForm.controls[type].value;






          share|improve this answer














          IN component, you can create a getter method which will return form control value.



          <form [formGroup]="studentForm">
          <p-dialog header="Student Detail" [(visible)]="displayStudentForm">
          <div class="p-grid">
          <label>Student Number</label>
          <label>getControlLabel('studentNumber')</label>
          </div>
          <div class="p-grid">
          <label>Student Age</label>
          <label>getControlLabel('studentAge')</label>
          </div>
          <div class="p-grid">
          <label>Student Type</label>
          <label>getControlLabel('studentType')</label>
          </div>
          </p-dialog>
          </form>


          Component:



          getControlLabel(type: string)
          return studentForm.controls[type].value;







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 11 at 12:28

























          answered Nov 11 at 12:17









          Suresh Kumar Ariya

          4,0551215




          4,0551215











          • Thanks for your reply @SureshKumarAriya. But in real scenario, there will be 30 label not 3. And foreach, I will write get method. I don't know, Is this proper and recomended way? Because, I'm looking recomended way for this?
            – Hasan Ozdemir
            Nov 11 at 12:20










          • Or should I use template driven forms for doing this @SureshKumarAriya ?
            – Hasan Ozdemir
            Nov 11 at 12:26






          • 1




            Updated the code. is it fine?
            – Suresh Kumar Ariya
            Nov 11 at 12:29






          • 1




            You can follow the first approach (i.e getter method) if we have around 10 form control labels. In your case its 30 right. Its suggessted way to call component method which will return form control value based on input value. I have used this in many places in our application and its a recommended one. Template Driven Form approach is like Angular JS approach, we won't prefer that as Angular 2+ is modern web framework.
            – Suresh Kumar Ariya
            Nov 11 at 12:36






          • 1




            Yes, you can use directive also. Its a good option
            – Suresh Kumar Ariya
            Nov 11 at 12:43
















          • Thanks for your reply @SureshKumarAriya. But in real scenario, there will be 30 label not 3. And foreach, I will write get method. I don't know, Is this proper and recomended way? Because, I'm looking recomended way for this?
            – Hasan Ozdemir
            Nov 11 at 12:20










          • Or should I use template driven forms for doing this @SureshKumarAriya ?
            – Hasan Ozdemir
            Nov 11 at 12:26






          • 1




            Updated the code. is it fine?
            – Suresh Kumar Ariya
            Nov 11 at 12:29






          • 1




            You can follow the first approach (i.e getter method) if we have around 10 form control labels. In your case its 30 right. Its suggessted way to call component method which will return form control value based on input value. I have used this in many places in our application and its a recommended one. Template Driven Form approach is like Angular JS approach, we won't prefer that as Angular 2+ is modern web framework.
            – Suresh Kumar Ariya
            Nov 11 at 12:36






          • 1




            Yes, you can use directive also. Its a good option
            – Suresh Kumar Ariya
            Nov 11 at 12:43















          Thanks for your reply @SureshKumarAriya. But in real scenario, there will be 30 label not 3. And foreach, I will write get method. I don't know, Is this proper and recomended way? Because, I'm looking recomended way for this?
          – Hasan Ozdemir
          Nov 11 at 12:20




          Thanks for your reply @SureshKumarAriya. But in real scenario, there will be 30 label not 3. And foreach, I will write get method. I don't know, Is this proper and recomended way? Because, I'm looking recomended way for this?
          – Hasan Ozdemir
          Nov 11 at 12:20












          Or should I use template driven forms for doing this @SureshKumarAriya ?
          – Hasan Ozdemir
          Nov 11 at 12:26




          Or should I use template driven forms for doing this @SureshKumarAriya ?
          – Hasan Ozdemir
          Nov 11 at 12:26




          1




          1




          Updated the code. is it fine?
          – Suresh Kumar Ariya
          Nov 11 at 12:29




          Updated the code. is it fine?
          – Suresh Kumar Ariya
          Nov 11 at 12:29




          1




          1




          You can follow the first approach (i.e getter method) if we have around 10 form control labels. In your case its 30 right. Its suggessted way to call component method which will return form control value based on input value. I have used this in many places in our application and its a recommended one. Template Driven Form approach is like Angular JS approach, we won't prefer that as Angular 2+ is modern web framework.
          – Suresh Kumar Ariya
          Nov 11 at 12:36




          You can follow the first approach (i.e getter method) if we have around 10 form control labels. In your case its 30 right. Its suggessted way to call component method which will return form control value based on input value. I have used this in many places in our application and its a recommended one. Template Driven Form approach is like Angular JS approach, we won't prefer that as Angular 2+ is modern web framework.
          – Suresh Kumar Ariya
          Nov 11 at 12:36




          1




          1




          Yes, you can use directive also. Its a good option
          – Suresh Kumar Ariya
          Nov 11 at 12:43




          Yes, you can use directive also. Its a good option
          – Suresh Kumar Ariya
          Nov 11 at 12:43

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248582%2fusing-formcontrolname-with-label-in-angular-6%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          What does pagestruct do in Eviews?

          Dutch intervention in Lombok and Karangasem

          Channel Islands