I need to print countries based on option selected in array in my code dynamicallyBinding select element to object in AngularHow do you remove all the options of a select box and then add one option and select it with jQuery?What is the best way to add options to a select from as a JS object with jQuery?Adding options to a <select> using jQuery?Frame Buster Buster … buster code neededSimplest code for array intersection in javascriptSelecting last element in JavaScript arrayjQuery Get Selected Option From DropdownWorking with select using AngularJS's ng-optionsReact JSX: selecting “selected” on selected <select> optionAngularJS - select option and use it in a function
Metric version of "footage"?
When is pointing out a person's hypocrisy not considered to be a logical fallacy?
Does Google Maps take into account hills/inclines for route times?
Too many spies!
Rearranging the formula
latinate or other words of foreign origin as opposed to Germanic words
Ambiguous sentences: How to tell when they need fixing?
P-MOSFET failing
How do I write a romance that doesn't look obvious
nginx serves wrong domain site. It doenst shows default site if no configuration applies
Why would guns not work in the dungeon?
Why did my rum cake turn black?
Is `curl something | sudo bash -` a reasonably safe installation method?
Filtering fine silt/mud from water (not necessarily bacteria etc.)
Can a continent naturally split into two distant parts within a week?
Is it rude to tell recruiters I would only change jobs for a better salary?
How might the United Kingdom become a republic?
What is the English equivalent of 干物女 (dried fish woman)?
I quit, and boss offered me 3 month "grace period" where I could still come back
Can anybody provide any information about this equation?
As a DM, how to avoid unconscious metagaming when dealing with a high AC character?
Why does java.time.Period#normalized() not normalize days?
Can you negate disadvantage on throwing a net by using the Lunging Attack maneuver of the Battle Master fighter?
Fix /dev/sdb after using dd with no device inserted
I need to print countries based on option selected in array in my code dynamically
Binding select element to object in AngularHow do you remove all the options of a select box and then add one option and select it with jQuery?What is the best way to add options to a select from as a JS object with jQuery?Adding options to a <select> using jQuery?Frame Buster Buster … buster code neededSimplest code for array intersection in javascriptSelecting last element in JavaScript arrayjQuery Get Selected Option From DropdownWorking with select using AngularJS's ng-optionsReact JSX: selecting “selected” on selected <select> optionAngularJS - select option and use it in a function
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I need simple code help. If I choose any particular letter then corresponding countries should be displayed, in my current position I am not able to do it dynamically.
For example if i choose letter A then countries pertaining to those should be displayed outside the select.
<select [(ngModel)]="selectedOption">
<option *ngFor="let o of options">
o.letter
</option>
</select>
<p *ngFor="let o of options">Countries are: o.countries </p>
export class AppComponent
selectedOption: string;
options = [
letter: "A", countries: ["Afghanistan", "Albania", "Argentina"] ,
letter: "B", countries: ["Bangladesh", "Bahamas", "Bahrain"]
]
If A chosen then Afghanistan Albania ....
If B chosen then ....
If C chosen then .... I should be able to expand array in future.
javascript angular typescript
add a comment |
I need simple code help. If I choose any particular letter then corresponding countries should be displayed, in my current position I am not able to do it dynamically.
For example if i choose letter A then countries pertaining to those should be displayed outside the select.
<select [(ngModel)]="selectedOption">
<option *ngFor="let o of options">
o.letter
</option>
</select>
<p *ngFor="let o of options">Countries are: o.countries </p>
export class AppComponent
selectedOption: string;
options = [
letter: "A", countries: ["Afghanistan", "Albania", "Argentina"] ,
letter: "B", countries: ["Bangladesh", "Bahamas", "Bahrain"]
]
If A chosen then Afghanistan Albania ....
If B chosen then ....
If C chosen then .... I should be able to expand array in future.
javascript angular typescript
add a comment |
I need simple code help. If I choose any particular letter then corresponding countries should be displayed, in my current position I am not able to do it dynamically.
For example if i choose letter A then countries pertaining to those should be displayed outside the select.
<select [(ngModel)]="selectedOption">
<option *ngFor="let o of options">
o.letter
</option>
</select>
<p *ngFor="let o of options">Countries are: o.countries </p>
export class AppComponent
selectedOption: string;
options = [
letter: "A", countries: ["Afghanistan", "Albania", "Argentina"] ,
letter: "B", countries: ["Bangladesh", "Bahamas", "Bahrain"]
]
If A chosen then Afghanistan Albania ....
If B chosen then ....
If C chosen then .... I should be able to expand array in future.
javascript angular typescript
I need simple code help. If I choose any particular letter then corresponding countries should be displayed, in my current position I am not able to do it dynamically.
For example if i choose letter A then countries pertaining to those should be displayed outside the select.
<select [(ngModel)]="selectedOption">
<option *ngFor="let o of options">
o.letter
</option>
</select>
<p *ngFor="let o of options">Countries are: o.countries </p>
export class AppComponent
selectedOption: string;
options = [
letter: "A", countries: ["Afghanistan", "Albania", "Argentina"] ,
letter: "B", countries: ["Bangladesh", "Bahamas", "Bahrain"]
]
If A chosen then Afghanistan Albania ....
If B chosen then ....
If C chosen then .... I should be able to expand array in future.
javascript angular typescript
javascript angular typescript
asked Mar 26 at 5:37
R.HR.H
8710 bronze badges
8710 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can use ngValue
instead of using ngFor
.
You can refer this answer.
Here is the working example.
Your code becomes
<select [(ngModel)]="selectedOption">
<option *ngFor="let o of options" [ngValue]="o">
o.letter
</option>
</select>
<!-- Just to debug and display selected object -->
json
<p>selectedOption.countries</p>
add a comment |
You can try this
<p *ngFor="let o of options">
<label *ngIf="o.letter === selectedOption">Countries are: o.countries <label>
</p>
Template parse errors: Can't have multiple template bindings on one element
– R.H
Mar 26 at 5:43
I've modified the answer. Could you try that?
– Seba Cherian
Mar 26 at 5:45
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%2f55350479%2fi-need-to-print-countries-based-on-option-selected-in-array-in-my-code-dynamical%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
You can use ngValue
instead of using ngFor
.
You can refer this answer.
Here is the working example.
Your code becomes
<select [(ngModel)]="selectedOption">
<option *ngFor="let o of options" [ngValue]="o">
o.letter
</option>
</select>
<!-- Just to debug and display selected object -->
json
<p>selectedOption.countries</p>
add a comment |
You can use ngValue
instead of using ngFor
.
You can refer this answer.
Here is the working example.
Your code becomes
<select [(ngModel)]="selectedOption">
<option *ngFor="let o of options" [ngValue]="o">
o.letter
</option>
</select>
<!-- Just to debug and display selected object -->
json
<p>selectedOption.countries</p>
add a comment |
You can use ngValue
instead of using ngFor
.
You can refer this answer.
Here is the working example.
Your code becomes
<select [(ngModel)]="selectedOption">
<option *ngFor="let o of options" [ngValue]="o">
o.letter
</option>
</select>
<!-- Just to debug and display selected object -->
json
<p>selectedOption.countries</p>
You can use ngValue
instead of using ngFor
.
You can refer this answer.
Here is the working example.
Your code becomes
<select [(ngModel)]="selectedOption">
<option *ngFor="let o of options" [ngValue]="o">
o.letter
</option>
</select>
<!-- Just to debug and display selected object -->
json
<p>selectedOption.countries</p>
answered Mar 26 at 5:47
Laxmikant DangeLaxmikant Dange
5,7013 gold badges31 silver badges57 bronze badges
5,7013 gold badges31 silver badges57 bronze badges
add a comment |
add a comment |
You can try this
<p *ngFor="let o of options">
<label *ngIf="o.letter === selectedOption">Countries are: o.countries <label>
</p>
Template parse errors: Can't have multiple template bindings on one element
– R.H
Mar 26 at 5:43
I've modified the answer. Could you try that?
– Seba Cherian
Mar 26 at 5:45
add a comment |
You can try this
<p *ngFor="let o of options">
<label *ngIf="o.letter === selectedOption">Countries are: o.countries <label>
</p>
Template parse errors: Can't have multiple template bindings on one element
– R.H
Mar 26 at 5:43
I've modified the answer. Could you try that?
– Seba Cherian
Mar 26 at 5:45
add a comment |
You can try this
<p *ngFor="let o of options">
<label *ngIf="o.letter === selectedOption">Countries are: o.countries <label>
</p>
You can try this
<p *ngFor="let o of options">
<label *ngIf="o.letter === selectedOption">Countries are: o.countries <label>
</p>
edited Mar 26 at 6:01
Bhagwat Tupe
8054 silver badges19 bronze badges
8054 silver badges19 bronze badges
answered Mar 26 at 5:40
Seba CherianSeba Cherian
8791 silver badge14 bronze badges
8791 silver badge14 bronze badges
Template parse errors: Can't have multiple template bindings on one element
– R.H
Mar 26 at 5:43
I've modified the answer. Could you try that?
– Seba Cherian
Mar 26 at 5:45
add a comment |
Template parse errors: Can't have multiple template bindings on one element
– R.H
Mar 26 at 5:43
I've modified the answer. Could you try that?
– Seba Cherian
Mar 26 at 5:45
Template parse errors: Can't have multiple template bindings on one element
– R.H
Mar 26 at 5:43
Template parse errors: Can't have multiple template bindings on one element
– R.H
Mar 26 at 5:43
I've modified the answer. Could you try that?
– Seba Cherian
Mar 26 at 5:45
I've modified the answer. Could you try that?
– Seba Cherian
Mar 26 at 5:45
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%2f55350479%2fi-need-to-print-countries-based-on-option-selected-in-array-in-my-code-dynamical%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