angular6 cannot set the value of ngForm from component.tsAngular6, Cannot add new dataAngular6 how to keep adding dropdown with selected valuesHow to iterate the keys and values in Angular6Angular6 :How to iterate the keys and values without Pipecheck if more than 1 value in an array in angular6how to edit template driven form values in angular6How to set default values in ng-select in angular6?Set value for angular6 select option using reactive FormGroup or FormControlNameHow to set value to a Reactive Form control in Angular6?

SQL Server table with 4,000,000 rows is 40GB

Is there a sentence that begins with “them”?

Have there been any countries that voted themselves out of existence?

How can "life" insurance prevent the cheapening of death?

How should we understand "unobscured by flying friends" in this context?

Will replacing a fake visa with a different fake visa cause me problems when applying for a legal study permit?

How flexible are number-of-pages submission guidelines for conferences?

Why does F + F' = 1?

Should I use my toaster oven for slow roasting?

How to create a list of dictionaries from a dictionary with lists of different lengths

Georgian capital letter “Ⴒ” (“tar”) in pdfLaTeX

What is this dollar sign ($) icon in my Menu Bar?

Why would "an mule" be used instead of "a mule"?

How do I politely hint customers to leave my store, without pretending to need leave store myself?

Expected value until a success?

SCOTUS - Can Congress overrule Marbury v. Madison by statute?

What's the biggest difference between these two photos?

Where does the expression "triple-A" comes from?

Are programming languages necessary/useful for operations research practitioner?

Could the government trigger by-elections to regain a majority?

Writing a love interest for my hero

Are there take-over requests from autopilots?

Wrathful Smite, and the term 'Creature'

Can board a plane to Cameroon without a Cameroonian visa?



angular6 cannot set the value of ngForm from component.ts


Angular6, Cannot add new dataAngular6 how to keep adding dropdown with selected valuesHow to iterate the keys and values in Angular6Angular6 :How to iterate the keys and values without Pipecheck if more than 1 value in an array in angular6how to edit template driven form values in angular6How to set default values in ng-select in angular6?Set value for angular6 select option using reactive FormGroup or FormControlNameHow to set value to a Reactive Form control in Angular6?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















i am developing an basic angular 6 application that fetches the data, display it in the table, each row has delete, edit button this is one component 'detail list', i have another component as 'detail component' that are having controls to add the record in the table, i am fetching the data from the webapi, adding the record and deleting the record using the same webapi, they all are working fine, now i want to edit the record from the table, i am using the same webapi to fetch the data, webapi returning the record, i want to display this record's data in the 'detail component', the same component that is used to add the record, so at the component i am calling ngAfterViewInit()



>



 ngAfterViewInit() 
this.service.change.subscribe((data: Patient) =>
alert('in the detail component of ngAfterViewInit');
console.log(data);
this.ModelChange(data);
) ;



and the code for the ModelChange is as follows




ModelChange(data: Patient)
this.form.controls['PatientCode'].setValue(data.PatientCode);






and my html is like







<form #form="ngForm" autocomplete="on" (submit)="OnSubmit(form)">
<div class="row">
<div class="form-group">
<input name="PatientCode" [(ngModel)]="PatientCode"class="form-control" placeholder ="Patient Code" (ngModelChange)="ModelChange(event)" required>

</div>
<div class="col-md -3 form-group">
<input name="FirstName" [(ngModel)] ="FirstName" class="form-control" placeholder="First Name" required>

</div>
<div class=" col-md-5 form-group">
<input name="LastName" [(ngModel)]="LastName" class="form-control" placeholder="Last Name" required>

</div>
</div>
<div class="row">
<div class="form-group">
<input name="MRN" class="form-control" [(ngModel)]="MRN" placeholder="MRN" required>

</div>
<div class="col-md-3 form-group">
<!--<input name="DateOfBirth" class="form-control" placeholder="Date of Birth">-->
<ejs-datepicker name="DateOfBirth" [(ngModel)]="DateOfBirth" id='datepicker' placeholder='Enter Date Of Birth' [value]='value' [min]='minDate' [max]='maxDate'></ejs-datepicker>

</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<button type="submit" (click)="AddPatient(p)" class="btn btn-success center-block "> Add Patient</button>
</div>
<div class="col-md-13">
<button type="submit" (click)="EditPatient(p)" class="btn btn-success center-block "> Edit Patient</button>
</div>

</div>
</form>


at the console i am getting error that cannot Cannot read property 'controls' of undefined



Please help me out what is the correct way of setting the control property with the fetched data










share|improve this question






























    1















    i am developing an basic angular 6 application that fetches the data, display it in the table, each row has delete, edit button this is one component 'detail list', i have another component as 'detail component' that are having controls to add the record in the table, i am fetching the data from the webapi, adding the record and deleting the record using the same webapi, they all are working fine, now i want to edit the record from the table, i am using the same webapi to fetch the data, webapi returning the record, i want to display this record's data in the 'detail component', the same component that is used to add the record, so at the component i am calling ngAfterViewInit()



    >



     ngAfterViewInit() 
    this.service.change.subscribe((data: Patient) =>
    alert('in the detail component of ngAfterViewInit');
    console.log(data);
    this.ModelChange(data);
    ) ;



    and the code for the ModelChange is as follows




    ModelChange(data: Patient)
    this.form.controls['PatientCode'].setValue(data.PatientCode);






    and my html is like







    <form #form="ngForm" autocomplete="on" (submit)="OnSubmit(form)">
    <div class="row">
    <div class="form-group">
    <input name="PatientCode" [(ngModel)]="PatientCode"class="form-control" placeholder ="Patient Code" (ngModelChange)="ModelChange(event)" required>

    </div>
    <div class="col-md -3 form-group">
    <input name="FirstName" [(ngModel)] ="FirstName" class="form-control" placeholder="First Name" required>

    </div>
    <div class=" col-md-5 form-group">
    <input name="LastName" [(ngModel)]="LastName" class="form-control" placeholder="Last Name" required>

    </div>
    </div>
    <div class="row">
    <div class="form-group">
    <input name="MRN" class="form-control" [(ngModel)]="MRN" placeholder="MRN" required>

    </div>
    <div class="col-md-3 form-group">
    <!--<input name="DateOfBirth" class="form-control" placeholder="Date of Birth">-->
    <ejs-datepicker name="DateOfBirth" [(ngModel)]="DateOfBirth" id='datepicker' placeholder='Enter Date Of Birth' [value]='value' [min]='minDate' [max]='maxDate'></ejs-datepicker>

    </div>
    </div>
    <div class="row">
    <div class="col-md-12 text-center">
    <button type="submit" (click)="AddPatient(p)" class="btn btn-success center-block "> Add Patient</button>
    </div>
    <div class="col-md-13">
    <button type="submit" (click)="EditPatient(p)" class="btn btn-success center-block "> Edit Patient</button>
    </div>

    </div>
    </form>


    at the console i am getting error that cannot Cannot read property 'controls' of undefined



    Please help me out what is the correct way of setting the control property with the fetched data










    share|improve this question


























      1












      1








      1








      i am developing an basic angular 6 application that fetches the data, display it in the table, each row has delete, edit button this is one component 'detail list', i have another component as 'detail component' that are having controls to add the record in the table, i am fetching the data from the webapi, adding the record and deleting the record using the same webapi, they all are working fine, now i want to edit the record from the table, i am using the same webapi to fetch the data, webapi returning the record, i want to display this record's data in the 'detail component', the same component that is used to add the record, so at the component i am calling ngAfterViewInit()



      >



       ngAfterViewInit() 
      this.service.change.subscribe((data: Patient) =>
      alert('in the detail component of ngAfterViewInit');
      console.log(data);
      this.ModelChange(data);
      ) ;



      and the code for the ModelChange is as follows




      ModelChange(data: Patient)
      this.form.controls['PatientCode'].setValue(data.PatientCode);






      and my html is like







      <form #form="ngForm" autocomplete="on" (submit)="OnSubmit(form)">
      <div class="row">
      <div class="form-group">
      <input name="PatientCode" [(ngModel)]="PatientCode"class="form-control" placeholder ="Patient Code" (ngModelChange)="ModelChange(event)" required>

      </div>
      <div class="col-md -3 form-group">
      <input name="FirstName" [(ngModel)] ="FirstName" class="form-control" placeholder="First Name" required>

      </div>
      <div class=" col-md-5 form-group">
      <input name="LastName" [(ngModel)]="LastName" class="form-control" placeholder="Last Name" required>

      </div>
      </div>
      <div class="row">
      <div class="form-group">
      <input name="MRN" class="form-control" [(ngModel)]="MRN" placeholder="MRN" required>

      </div>
      <div class="col-md-3 form-group">
      <!--<input name="DateOfBirth" class="form-control" placeholder="Date of Birth">-->
      <ejs-datepicker name="DateOfBirth" [(ngModel)]="DateOfBirth" id='datepicker' placeholder='Enter Date Of Birth' [value]='value' [min]='minDate' [max]='maxDate'></ejs-datepicker>

      </div>
      </div>
      <div class="row">
      <div class="col-md-12 text-center">
      <button type="submit" (click)="AddPatient(p)" class="btn btn-success center-block "> Add Patient</button>
      </div>
      <div class="col-md-13">
      <button type="submit" (click)="EditPatient(p)" class="btn btn-success center-block "> Edit Patient</button>
      </div>

      </div>
      </form>


      at the console i am getting error that cannot Cannot read property 'controls' of undefined



      Please help me out what is the correct way of setting the control property with the fetched data










      share|improve this question














      i am developing an basic angular 6 application that fetches the data, display it in the table, each row has delete, edit button this is one component 'detail list', i have another component as 'detail component' that are having controls to add the record in the table, i am fetching the data from the webapi, adding the record and deleting the record using the same webapi, they all are working fine, now i want to edit the record from the table, i am using the same webapi to fetch the data, webapi returning the record, i want to display this record's data in the 'detail component', the same component that is used to add the record, so at the component i am calling ngAfterViewInit()



      >



       ngAfterViewInit() 
      this.service.change.subscribe((data: Patient) =>
      alert('in the detail component of ngAfterViewInit');
      console.log(data);
      this.ModelChange(data);
      ) ;



      and the code for the ModelChange is as follows




      ModelChange(data: Patient)
      this.form.controls['PatientCode'].setValue(data.PatientCode);






      and my html is like







      <form #form="ngForm" autocomplete="on" (submit)="OnSubmit(form)">
      <div class="row">
      <div class="form-group">
      <input name="PatientCode" [(ngModel)]="PatientCode"class="form-control" placeholder ="Patient Code" (ngModelChange)="ModelChange(event)" required>

      </div>
      <div class="col-md -3 form-group">
      <input name="FirstName" [(ngModel)] ="FirstName" class="form-control" placeholder="First Name" required>

      </div>
      <div class=" col-md-5 form-group">
      <input name="LastName" [(ngModel)]="LastName" class="form-control" placeholder="Last Name" required>

      </div>
      </div>
      <div class="row">
      <div class="form-group">
      <input name="MRN" class="form-control" [(ngModel)]="MRN" placeholder="MRN" required>

      </div>
      <div class="col-md-3 form-group">
      <!--<input name="DateOfBirth" class="form-control" placeholder="Date of Birth">-->
      <ejs-datepicker name="DateOfBirth" [(ngModel)]="DateOfBirth" id='datepicker' placeholder='Enter Date Of Birth' [value]='value' [min]='minDate' [max]='maxDate'></ejs-datepicker>

      </div>
      </div>
      <div class="row">
      <div class="col-md-12 text-center">
      <button type="submit" (click)="AddPatient(p)" class="btn btn-success center-block "> Add Patient</button>
      </div>
      <div class="col-md-13">
      <button type="submit" (click)="EditPatient(p)" class="btn btn-success center-block "> Edit Patient</button>
      </div>

      </div>
      </form>


      at the console i am getting error that cannot Cannot read property 'controls' of undefined



      Please help me out what is the correct way of setting the control property with the fetched data







      angular6






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 28 at 7:35









      Sa faSa fa

      61 bronze badge




      61 bronze badge

























          0






          active

          oldest

          votes










          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',
          autoActivateHeartbeat: false,
          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/4.0/"u003ecc by-sa 4.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%2f55392291%2fangular6-cannot-set-the-value-of-ngform-from-component-ts%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes




          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







          Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.




















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55392291%2fangular6-cannot-set-the-value-of-ngform-from-component-ts%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







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript