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

          How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

          Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?