Angular5-Pass value of index to component
How should I pass the value of index of the option selected to the component.
<select (click)= "onpressed(i)" placeholder="select a value" class="custom-select" >
<option *ngFor="let data of data3; let i = index;" value = {{data.dash_name}} >
{{data.dash_name}}
</option>
</select>
angular
add a comment |
How should I pass the value of index of the option selected to the component.
<select (click)= "onpressed(i)" placeholder="select a value" class="custom-select" >
<option *ngFor="let data of data3; let i = index;" value = {{data.dash_name}} >
{{data.dash_name}}
</option>
</select>
angular
1
Post a clear and complete question, and post the relevant code in the question itself, as properly formatted text. Not as a link to an image.
– JB Nizet
Nov 14 '18 at 16:39
I have edited my question. @JBNizet
– user10648256
Nov 14 '18 at 16:58
add a comment |
How should I pass the value of index of the option selected to the component.
<select (click)= "onpressed(i)" placeholder="select a value" class="custom-select" >
<option *ngFor="let data of data3; let i = index;" value = {{data.dash_name}} >
{{data.dash_name}}
</option>
</select>
angular
How should I pass the value of index of the option selected to the component.
<select (click)= "onpressed(i)" placeholder="select a value" class="custom-select" >
<option *ngFor="let data of data3; let i = index;" value = {{data.dash_name}} >
{{data.dash_name}}
</option>
</select>
angular
angular
edited Nov 14 '18 at 16:57
user10648256
asked Nov 14 '18 at 16:33
user10648256user10648256
536
536
1
Post a clear and complete question, and post the relevant code in the question itself, as properly formatted text. Not as a link to an image.
– JB Nizet
Nov 14 '18 at 16:39
I have edited my question. @JBNizet
– user10648256
Nov 14 '18 at 16:58
add a comment |
1
Post a clear and complete question, and post the relevant code in the question itself, as properly formatted text. Not as a link to an image.
– JB Nizet
Nov 14 '18 at 16:39
I have edited my question. @JBNizet
– user10648256
Nov 14 '18 at 16:58
1
1
Post a clear and complete question, and post the relevant code in the question itself, as properly formatted text. Not as a link to an image.
– JB Nizet
Nov 14 '18 at 16:39
Post a clear and complete question, and post the relevant code in the question itself, as properly formatted text. Not as a link to an image.
– JB Nizet
Nov 14 '18 at 16:39
I have edited my question. @JBNizet
– user10648256
Nov 14 '18 at 16:58
I have edited my question. @JBNizet
– user10648256
Nov 14 '18 at 16:58
add a comment |
2 Answers
2
active
oldest
votes
Use like this.
<select (change)="onChange($event.target.selectedIndex)">
<option *ngFor="let item of items; let i=index;" [value]="item.value">{{item.value}}</option>
Component:
onChange(index){
console.log(index);
}
The value of index obtained in console is undefined.
– user10648256
Nov 14 '18 at 17:17
Updated the code. check now
– Suresh Kumar Ariya
Nov 14 '18 at 19:06
add a comment |
Live Example Relevant code in in files modalTest.component.ts and app.component.html
Try this:
<select class="form-control" [(ngModel)]="index">
<option *ngFor="let razon of razones; let i = index" [ngValue]="i">
{{razon.descRazon}}
</option>
</select>
In the component class
export class ModalTest {
razones = [{
descRazon:'testing Uno'
},{
descRazon:'testing Dos'
}]
index = 0;
constructor(){}
}
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%2f53304837%2fangular5-pass-value-of-index-to-component%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
Use like this.
<select (change)="onChange($event.target.selectedIndex)">
<option *ngFor="let item of items; let i=index;" [value]="item.value">{{item.value}}</option>
Component:
onChange(index){
console.log(index);
}
The value of index obtained in console is undefined.
– user10648256
Nov 14 '18 at 17:17
Updated the code. check now
– Suresh Kumar Ariya
Nov 14 '18 at 19:06
add a comment |
Use like this.
<select (change)="onChange($event.target.selectedIndex)">
<option *ngFor="let item of items; let i=index;" [value]="item.value">{{item.value}}</option>
Component:
onChange(index){
console.log(index);
}
The value of index obtained in console is undefined.
– user10648256
Nov 14 '18 at 17:17
Updated the code. check now
– Suresh Kumar Ariya
Nov 14 '18 at 19:06
add a comment |
Use like this.
<select (change)="onChange($event.target.selectedIndex)">
<option *ngFor="let item of items; let i=index;" [value]="item.value">{{item.value}}</option>
Component:
onChange(index){
console.log(index);
}
Use like this.
<select (change)="onChange($event.target.selectedIndex)">
<option *ngFor="let item of items; let i=index;" [value]="item.value">{{item.value}}</option>
Component:
onChange(index){
console.log(index);
}
edited Nov 14 '18 at 19:07
answered Nov 14 '18 at 16:41
Suresh Kumar AriyaSuresh Kumar Ariya
4,6611215
4,6611215
The value of index obtained in console is undefined.
– user10648256
Nov 14 '18 at 17:17
Updated the code. check now
– Suresh Kumar Ariya
Nov 14 '18 at 19:06
add a comment |
The value of index obtained in console is undefined.
– user10648256
Nov 14 '18 at 17:17
Updated the code. check now
– Suresh Kumar Ariya
Nov 14 '18 at 19:06
The value of index obtained in console is undefined.
– user10648256
Nov 14 '18 at 17:17
The value of index obtained in console is undefined.
– user10648256
Nov 14 '18 at 17:17
Updated the code. check now
– Suresh Kumar Ariya
Nov 14 '18 at 19:06
Updated the code. check now
– Suresh Kumar Ariya
Nov 14 '18 at 19:06
add a comment |
Live Example Relevant code in in files modalTest.component.ts and app.component.html
Try this:
<select class="form-control" [(ngModel)]="index">
<option *ngFor="let razon of razones; let i = index" [ngValue]="i">
{{razon.descRazon}}
</option>
</select>
In the component class
export class ModalTest {
razones = [{
descRazon:'testing Uno'
},{
descRazon:'testing Dos'
}]
index = 0;
constructor(){}
}
add a comment |
Live Example Relevant code in in files modalTest.component.ts and app.component.html
Try this:
<select class="form-control" [(ngModel)]="index">
<option *ngFor="let razon of razones; let i = index" [ngValue]="i">
{{razon.descRazon}}
</option>
</select>
In the component class
export class ModalTest {
razones = [{
descRazon:'testing Uno'
},{
descRazon:'testing Dos'
}]
index = 0;
constructor(){}
}
add a comment |
Live Example Relevant code in in files modalTest.component.ts and app.component.html
Try this:
<select class="form-control" [(ngModel)]="index">
<option *ngFor="let razon of razones; let i = index" [ngValue]="i">
{{razon.descRazon}}
</option>
</select>
In the component class
export class ModalTest {
razones = [{
descRazon:'testing Uno'
},{
descRazon:'testing Dos'
}]
index = 0;
constructor(){}
}
Live Example Relevant code in in files modalTest.component.ts and app.component.html
Try this:
<select class="form-control" [(ngModel)]="index">
<option *ngFor="let razon of razones; let i = index" [ngValue]="i">
{{razon.descRazon}}
</option>
</select>
In the component class
export class ModalTest {
razones = [{
descRazon:'testing Uno'
},{
descRazon:'testing Dos'
}]
index = 0;
constructor(){}
}
answered Nov 14 '18 at 16:55
Gabriel LopezGabriel Lopez
28217
28217
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%2f53304837%2fangular5-pass-value-of-index-to-component%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
1
Post a clear and complete question, and post the relevant code in the question itself, as properly formatted text. Not as a link to an image.
– JB Nizet
Nov 14 '18 at 16:39
I have edited my question. @JBNizet
– user10648256
Nov 14 '18 at 16:58