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;
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
add a comment |
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
please check answer with solution here stackblitz.com/edit/angular-r1gyo9?file=src/app/…
– TheParam
Mar 25 at 9:30
add a comment |
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
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
angular
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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
add a comment |
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
Its working bro thanks for your response.
– Siva
Mar 25 at 10:02
add a comment |
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>
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
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
add a comment |
add a comment |
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
Its working bro thanks for your response.
– Siva
Mar 25 at 10:02
add a comment |
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
Its working bro thanks for your response.
– Siva
Mar 25 at 10:02
add a comment |
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
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
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
add a comment |
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
add a comment |
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>
add a comment |
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>
add a comment |
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>
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>
answered Mar 25 at 9:39
RomaRoma
2091 silver badge12 bronze badges
2091 silver badge12 bronze badges
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
please check answer with solution here stackblitz.com/edit/angular-r1gyo9?file=src/app/…
– TheParam
Mar 25 at 9:30