How to display matched data in Angular 5How to use jQuery with Angular?Angular HTML bindingHow to detect a route change in Angular?Angular EXCEPTION: No provider for HttpAngular - Set headers for every requestWhat is the equivalent of ngShow and ngHide in Angular 2+?How to bundle an Angular app for productionAngular/RxJs When should I unsubscribe from `Subscription`Huge number of files generated for every Angular projectHow to display multiple value array in a card using angular 4

Does x-ray lead paint detection find lead underneath latex topcoats?

Accidentals and ties

How do I respond to requests for a "guarantee" not to leave after a few months?

Why do some games show lights shine thorugh walls?

Can any NP-Complete Problem be solved using at most polynomial space (but while using exponential time?)

Would it be a copyright violation if I made a character’s full name refer to a song?

How long would it take to cross the Channel in 1890's?

Is there a way to split the metadata to custom folders?

STM Microcontroller burns every time

Should I prioritize my 401(k) over my student loans?

Why is C++ initial allocation so much larger than C's?

Does Marvel have an equivalent of the Green Lantern?

Why is the voltage measurement of this circuit different when the switch is on?

Is it possible writing coservation of relativistic energy in this naive way?

Why do some professors with PhDs leave their professorships to teach high school?

Should my manager be aware of private LinkedIn approaches I receive? How to politely have this happen?

Why is the high-pass filter result in a discrete wavelet transform (DWT) downsampled?

Why cruise at 7000' in an A319?

Did Karl Marx ever use any example that involved cotton and dollars to illustrate the way capital and surplus value were generated?

Can Ogre clerics use Purify Food and Drink on humanoid characters?

Has there been any indication at all that further negotiation between the UK and EU is possible?

Is a single radon-daughter atom in air a solid?

Hot coffee brewing solutions for deep woods camping

Underbar nabla symbol doesn't work



How to display matched data in Angular 5


How to use jQuery with Angular?Angular HTML bindingHow to detect a route change in Angular?Angular EXCEPTION: No provider for HttpAngular - Set headers for every requestWhat is the equivalent of ngShow and ngHide in Angular 2+?How to bundle an Angular app for productionAngular/RxJs When should I unsubscribe from `Subscription`Huge number of files generated for every Angular projectHow to display multiple value array in a card using angular 4






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








0















Initially, I am displaying student details from this array in HTML along with a text box.



component.ts



students=[id:1,name:"john", id:2,name:"dublin",
id:3,name:"bhaskar",id:4,name:"robert"]


component.html



<div *ngFor="let x of students;let i=index">
x.name
<input type="text" [name]="'name'+i" >
</div>


Now I am getting 2 student details from database in an array



studentDetails=[name:"john",marks:50,name:"robert",marks:100]


Now what I need is student name is matched with students array of the name then the marks will display in the particular text field



I got this link but he took empty objects in the array.
stackblitz



I feel this is not the correct way.
Anyone, please help.










share|improve this question
























  • please check answer with solution here stackblitz.com/edit/angular-r1gyo9?file=src/app/…

    – TheParam
    Mar 25 at 9:30

















0















Initially, I am displaying student details from this array in HTML along with a text box.



component.ts



students=[id:1,name:"john", id:2,name:"dublin",
id:3,name:"bhaskar",id:4,name:"robert"]


component.html



<div *ngFor="let x of students;let i=index">
x.name
<input type="text" [name]="'name'+i" >
</div>


Now I am getting 2 student details from database in an array



studentDetails=[name:"john",marks:50,name:"robert",marks:100]


Now what I need is student name is matched with students array of the name then the marks will display in the particular text field



I got this link but he took empty objects in the array.
stackblitz



I feel this is not the correct way.
Anyone, please help.










share|improve this question
























  • please check answer with solution here stackblitz.com/edit/angular-r1gyo9?file=src/app/…

    – TheParam
    Mar 25 at 9:30













0












0








0








Initially, I am displaying student details from this array in HTML along with a text box.



component.ts



students=[id:1,name:"john", id:2,name:"dublin",
id:3,name:"bhaskar",id:4,name:"robert"]


component.html



<div *ngFor="let x of students;let i=index">
x.name
<input type="text" [name]="'name'+i" >
</div>


Now I am getting 2 student details from database in an array



studentDetails=[name:"john",marks:50,name:"robert",marks:100]


Now what I need is student name is matched with students array of the name then the marks will display in the particular text field



I got this link but he took empty objects in the array.
stackblitz



I feel this is not the correct way.
Anyone, please help.










share|improve this question
















Initially, I am displaying student details from this array in HTML along with a text box.



component.ts



students=[id:1,name:"john", id:2,name:"dublin",
id:3,name:"bhaskar",id:4,name:"robert"]


component.html



<div *ngFor="let x of students;let i=index">
x.name
<input type="text" [name]="'name'+i" >
</div>


Now I am getting 2 student details from database in an array



studentDetails=[name:"john",marks:50,name:"robert",marks:100]


Now what I need is student name is matched with students array of the name then the marks will display in the particular text field



I got this link but he took empty objects in the array.
stackblitz



I feel this is not the correct way.
Anyone, please help.







angular






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 9:46









TheParam

5,2951 gold badge19 silver badges31 bronze badges




5,2951 gold badge19 silver badges31 bronze badges










asked Mar 25 at 9:16









SivaSiva

94 bronze badges




94 bronze badges












  • please check answer with solution here stackblitz.com/edit/angular-r1gyo9?file=src/app/…

    – TheParam
    Mar 25 at 9:30

















  • please check answer with solution here stackblitz.com/edit/angular-r1gyo9?file=src/app/…

    – TheParam
    Mar 25 at 9:30
















please check answer with solution here stackblitz.com/edit/angular-r1gyo9?file=src/app/…

– TheParam
Mar 25 at 9:30





please check answer with solution here stackblitz.com/edit/angular-r1gyo9?file=src/app/…

– TheParam
Mar 25 at 9:30












3 Answers
3






active

oldest

votes


















1














Here you need to match the student name with studentDetails array of objects and return the match student marks like below.



Example



component.ts



 getStudentMarks(studentName) : number 
let marks = 0;
this.studentDetails.forEach(details =>

if (studentName == details.name)
marks = details.marks;

)
return marks;



component.html



<div *ngFor="let x of students;let i=index">
x.name
<input type="text" [value]="getStudentMarks(x.name)" >
</div>


Here is solution on stackblitz






share|improve this answer
































    0














    You can bind Marks field before hand and then when student details come from DB just update it like below



    students=[id:1,name:"john",id:2,name:"dublin",id:3,name:"bhaskar",id:4,name:"robert"]


    HTML



    <div *ngFor="let x of students;let i=index">
    x.name
    <input type="text" [name]="'name'+i" [(ngModel)]="x.marks">
    </div>


    once you get data from DB you just need to update original stident array and update marks in that



    studentDetails=[name:"john",marks:50,name:"robert",marks:100]

    for(let student of studentDetails)
    let matchedStudent= students.find(w=>w.name === student.name);
    if(matchedStudent)

    matchedStudent.marks=student.marks;




    Since here using two way data model .. your html will update once model get updated



    Note: But make sure name is unique field, generally it should be Id






    share|improve this answer

























    • Its working bro thanks for your response.

      – Siva
      Mar 25 at 10:02


















    0














    on component.html add following code:



    <div *ngFor="let x of students;let i=index">
    <div *ngFor="let j of studentDetails">
    <input *ngIf="x.name == j.name" type="text" [name]="'name'+i"
    [value]="j.marks">
    </div>
    </div>





    share|improve this answer

























      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/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%2f55334533%2fhow-to-display-matched-data-in-angular-5%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Here you need to match the student name with studentDetails array of objects and return the match student marks like below.



      Example



      component.ts



       getStudentMarks(studentName) : number 
      let marks = 0;
      this.studentDetails.forEach(details =>

      if (studentName == details.name)
      marks = details.marks;

      )
      return marks;



      component.html



      <div *ngFor="let x of students;let i=index">
      x.name
      <input type="text" [value]="getStudentMarks(x.name)" >
      </div>


      Here is solution on stackblitz






      share|improve this answer





























        1














        Here you need to match the student name with studentDetails array of objects and return the match student marks like below.



        Example



        component.ts



         getStudentMarks(studentName) : number 
        let marks = 0;
        this.studentDetails.forEach(details =>

        if (studentName == details.name)
        marks = details.marks;

        )
        return marks;



        component.html



        <div *ngFor="let x of students;let i=index">
        x.name
        <input type="text" [value]="getStudentMarks(x.name)" >
        </div>


        Here is solution on stackblitz






        share|improve this answer



























          1












          1








          1







          Here you need to match the student name with studentDetails array of objects and return the match student marks like below.



          Example



          component.ts



           getStudentMarks(studentName) : number 
          let marks = 0;
          this.studentDetails.forEach(details =>

          if (studentName == details.name)
          marks = details.marks;

          )
          return marks;



          component.html



          <div *ngFor="let x of students;let i=index">
          x.name
          <input type="text" [value]="getStudentMarks(x.name)" >
          </div>


          Here is solution on stackblitz






          share|improve this answer















          Here you need to match the student name with studentDetails array of objects and return the match student marks like below.



          Example



          component.ts



           getStudentMarks(studentName) : number 
          let marks = 0;
          this.studentDetails.forEach(details =>

          if (studentName == details.name)
          marks = details.marks;

          )
          return marks;



          component.html



          <div *ngFor="let x of students;let i=index">
          x.name
          <input type="text" [value]="getStudentMarks(x.name)" >
          </div>


          Here is solution on stackblitz







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 25 at 9:45

























          answered Mar 25 at 9:25









          TheParamTheParam

          5,2951 gold badge19 silver badges31 bronze badges




          5,2951 gold badge19 silver badges31 bronze badges























              0














              You can bind Marks field before hand and then when student details come from DB just update it like below



              students=[id:1,name:"john",id:2,name:"dublin",id:3,name:"bhaskar",id:4,name:"robert"]


              HTML



              <div *ngFor="let x of students;let i=index">
              x.name
              <input type="text" [name]="'name'+i" [(ngModel)]="x.marks">
              </div>


              once you get data from DB you just need to update original stident array and update marks in that



              studentDetails=[name:"john",marks:50,name:"robert",marks:100]

              for(let student of studentDetails)
              let matchedStudent= students.find(w=>w.name === student.name);
              if(matchedStudent)

              matchedStudent.marks=student.marks;




              Since here using two way data model .. your html will update once model get updated



              Note: But make sure name is unique field, generally it should be Id






              share|improve this answer

























              • Its working bro thanks for your response.

                – Siva
                Mar 25 at 10:02















              0














              You can bind Marks field before hand and then when student details come from DB just update it like below



              students=[id:1,name:"john",id:2,name:"dublin",id:3,name:"bhaskar",id:4,name:"robert"]


              HTML



              <div *ngFor="let x of students;let i=index">
              x.name
              <input type="text" [name]="'name'+i" [(ngModel)]="x.marks">
              </div>


              once you get data from DB you just need to update original stident array and update marks in that



              studentDetails=[name:"john",marks:50,name:"robert",marks:100]

              for(let student of studentDetails)
              let matchedStudent= students.find(w=>w.name === student.name);
              if(matchedStudent)

              matchedStudent.marks=student.marks;




              Since here using two way data model .. your html will update once model get updated



              Note: But make sure name is unique field, generally it should be Id






              share|improve this answer

























              • Its working bro thanks for your response.

                – Siva
                Mar 25 at 10:02













              0












              0








              0







              You can bind Marks field before hand and then when student details come from DB just update it like below



              students=[id:1,name:"john",id:2,name:"dublin",id:3,name:"bhaskar",id:4,name:"robert"]


              HTML



              <div *ngFor="let x of students;let i=index">
              x.name
              <input type="text" [name]="'name'+i" [(ngModel)]="x.marks">
              </div>


              once you get data from DB you just need to update original stident array and update marks in that



              studentDetails=[name:"john",marks:50,name:"robert",marks:100]

              for(let student of studentDetails)
              let matchedStudent= students.find(w=>w.name === student.name);
              if(matchedStudent)

              matchedStudent.marks=student.marks;




              Since here using two way data model .. your html will update once model get updated



              Note: But make sure name is unique field, generally it should be Id






              share|improve this answer















              You can bind Marks field before hand and then when student details come from DB just update it like below



              students=[id:1,name:"john",id:2,name:"dublin",id:3,name:"bhaskar",id:4,name:"robert"]


              HTML



              <div *ngFor="let x of students;let i=index">
              x.name
              <input type="text" [name]="'name'+i" [(ngModel)]="x.marks">
              </div>


              once you get data from DB you just need to update original stident array and update marks in that



              studentDetails=[name:"john",marks:50,name:"robert",marks:100]

              for(let student of studentDetails)
              let matchedStudent= students.find(w=>w.name === student.name);
              if(matchedStudent)

              matchedStudent.marks=student.marks;




              Since here using two way data model .. your html will update once model get updated



              Note: But make sure name is unique field, generally it should be Id







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Mar 25 at 9:33

























              answered Mar 25 at 9:28









              RajivRajiv

              6236 silver badges14 bronze badges




              6236 silver badges14 bronze badges












              • Its working bro thanks for your response.

                – Siva
                Mar 25 at 10:02

















              • Its working bro thanks for your response.

                – Siva
                Mar 25 at 10:02
















              Its working bro thanks for your response.

              – Siva
              Mar 25 at 10:02





              Its working bro thanks for your response.

              – Siva
              Mar 25 at 10:02











              0














              on component.html add following code:



              <div *ngFor="let x of students;let i=index">
              <div *ngFor="let j of studentDetails">
              <input *ngIf="x.name == j.name" type="text" [name]="'name'+i"
              [value]="j.marks">
              </div>
              </div>





              share|improve this answer



























                0














                on component.html add following code:



                <div *ngFor="let x of students;let i=index">
                <div *ngFor="let j of studentDetails">
                <input *ngIf="x.name == j.name" type="text" [name]="'name'+i"
                [value]="j.marks">
                </div>
                </div>





                share|improve this answer

























                  0












                  0








                  0







                  on component.html add following code:



                  <div *ngFor="let x of students;let i=index">
                  <div *ngFor="let j of studentDetails">
                  <input *ngIf="x.name == j.name" type="text" [name]="'name'+i"
                  [value]="j.marks">
                  </div>
                  </div>





                  share|improve this answer













                  on component.html add following code:



                  <div *ngFor="let x of students;let i=index">
                  <div *ngFor="let j of studentDetails">
                  <input *ngIf="x.name == j.name" type="text" [name]="'name'+i"
                  [value]="j.marks">
                  </div>
                  </div>






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 25 at 9:39









                  RomaRoma

                  2091 silver badge12 bronze badges




                  2091 silver badge12 bronze badges



























                      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%2f55334533%2fhow-to-display-matched-data-in-angular-5%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

                      SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                      은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현