Adding dynamically added field values along with form values in angular
I have an component called demo
, which as some i/p fields:
first name,last name,number.... along with these fields i am dynamically adding the 2 fields (i,e to add multiple address).
I am able to send the all form fields value but not the dynamically added values.
While logging the dynamically added field values are displaying as undefined
. Since the component's code is long, I am posting stackblitz DEMO.
angular typescript angular6
add a comment |
I have an component called demo
, which as some i/p fields:
first name,last name,number.... along with these fields i am dynamically adding the 2 fields (i,e to add multiple address).
I am able to send the all form fields value but not the dynamically added values.
While logging the dynamically added field values are displaying as undefined
. Since the component's code is long, I am posting stackblitz DEMO.
angular typescript angular6
which 2 fields are you talking about? addresses are the array.
– Just code
Dec 31 '18 at 4:19
Just fill allinput fields
and also thedynamic fields
and hit theSave
button then see theconsole
, Then you can understand my issue.
– Empty_Soul
Dec 31 '18 at 4:25
add a comment |
I have an component called demo
, which as some i/p fields:
first name,last name,number.... along with these fields i am dynamically adding the 2 fields (i,e to add multiple address).
I am able to send the all form fields value but not the dynamically added values.
While logging the dynamically added field values are displaying as undefined
. Since the component's code is long, I am posting stackblitz DEMO.
angular typescript angular6
I have an component called demo
, which as some i/p fields:
first name,last name,number.... along with these fields i am dynamically adding the 2 fields (i,e to add multiple address).
I am able to send the all form fields value but not the dynamically added values.
While logging the dynamically added field values are displaying as undefined
. Since the component's code is long, I am posting stackblitz DEMO.
angular typescript angular6
angular typescript angular6
asked Dec 31 '18 at 4:09
Empty_SoulEmpty_Soul
31611
31611
which 2 fields are you talking about? addresses are the array.
– Just code
Dec 31 '18 at 4:19
Just fill allinput fields
and also thedynamic fields
and hit theSave
button then see theconsole
, Then you can understand my issue.
– Empty_Soul
Dec 31 '18 at 4:25
add a comment |
which 2 fields are you talking about? addresses are the array.
– Just code
Dec 31 '18 at 4:19
Just fill allinput fields
and also thedynamic fields
and hit theSave
button then see theconsole
, Then you can understand my issue.
– Empty_Soul
Dec 31 '18 at 4:25
which 2 fields are you talking about? addresses are the array.
– Just code
Dec 31 '18 at 4:19
which 2 fields are you talking about? addresses are the array.
– Just code
Dec 31 '18 at 4:19
Just fill all
input fields
and also the dynamic fields
and hit the Save
button then see the console
, Then you can understand my issue.– Empty_Soul
Dec 31 '18 at 4:25
Just fill all
input fields
and also the dynamic fields
and hit the Save
button then see the console
, Then you can understand my issue.– Empty_Soul
Dec 31 '18 at 4:25
add a comment |
1 Answer
1
active
oldest
votes
As addresstype is array and your will not be able to get it easily,
addFieldValue() {
if (this.newAttribute.adr && this.newAttribute.city) {
if (this.fieldArray.indexOf(this.newAttribute) === -1) {
this.fieldArray.push(this.newAttribute)
}
}
this.newAttribute = {};//see here
}
Here you are actually emptying the value so the values will be always 0.
But you are already putting the values in the fieldArray, you can easily retrieve the array values by iterating over it and getting the values.
public onAdd(): void {
this.someContact = this.addForm.value;
this.someContact.phoneNumbers = ;
const phno: IPhoneNumber = {
countryCode: this.addForm.value.counrtycode,
number: this.addForm.value.phonenumber,
};
this.someContact.phoneNumbers.push(phno);
this.someContact.addresses = ;
this.fieldArray.forEach(a => {
const addr: IPostalAddress = {
addtype: a.adr,
city: a.city,
};
this.someContact.addresses.push(addr);
})
console.log(this.someContact);
}
I changed type
to addtype
, looks bad naming.
export interface IPostalAddress {
addtype: string;
city: string;
}
Demo
Note: as you are not dealing with the forms you can remove formControlName="adrType"
1
Thanks for answer and also for your valuable explanation regarding my issue.
– Empty_Soul
Dec 31 '18 at 4:33
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%2f53983501%2fadding-dynamically-added-field-values-along-with-form-values-in-angular%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As addresstype is array and your will not be able to get it easily,
addFieldValue() {
if (this.newAttribute.adr && this.newAttribute.city) {
if (this.fieldArray.indexOf(this.newAttribute) === -1) {
this.fieldArray.push(this.newAttribute)
}
}
this.newAttribute = {};//see here
}
Here you are actually emptying the value so the values will be always 0.
But you are already putting the values in the fieldArray, you can easily retrieve the array values by iterating over it and getting the values.
public onAdd(): void {
this.someContact = this.addForm.value;
this.someContact.phoneNumbers = ;
const phno: IPhoneNumber = {
countryCode: this.addForm.value.counrtycode,
number: this.addForm.value.phonenumber,
};
this.someContact.phoneNumbers.push(phno);
this.someContact.addresses = ;
this.fieldArray.forEach(a => {
const addr: IPostalAddress = {
addtype: a.adr,
city: a.city,
};
this.someContact.addresses.push(addr);
})
console.log(this.someContact);
}
I changed type
to addtype
, looks bad naming.
export interface IPostalAddress {
addtype: string;
city: string;
}
Demo
Note: as you are not dealing with the forms you can remove formControlName="adrType"
1
Thanks for answer and also for your valuable explanation regarding my issue.
– Empty_Soul
Dec 31 '18 at 4:33
add a comment |
As addresstype is array and your will not be able to get it easily,
addFieldValue() {
if (this.newAttribute.adr && this.newAttribute.city) {
if (this.fieldArray.indexOf(this.newAttribute) === -1) {
this.fieldArray.push(this.newAttribute)
}
}
this.newAttribute = {};//see here
}
Here you are actually emptying the value so the values will be always 0.
But you are already putting the values in the fieldArray, you can easily retrieve the array values by iterating over it and getting the values.
public onAdd(): void {
this.someContact = this.addForm.value;
this.someContact.phoneNumbers = ;
const phno: IPhoneNumber = {
countryCode: this.addForm.value.counrtycode,
number: this.addForm.value.phonenumber,
};
this.someContact.phoneNumbers.push(phno);
this.someContact.addresses = ;
this.fieldArray.forEach(a => {
const addr: IPostalAddress = {
addtype: a.adr,
city: a.city,
};
this.someContact.addresses.push(addr);
})
console.log(this.someContact);
}
I changed type
to addtype
, looks bad naming.
export interface IPostalAddress {
addtype: string;
city: string;
}
Demo
Note: as you are not dealing with the forms you can remove formControlName="adrType"
1
Thanks for answer and also for your valuable explanation regarding my issue.
– Empty_Soul
Dec 31 '18 at 4:33
add a comment |
As addresstype is array and your will not be able to get it easily,
addFieldValue() {
if (this.newAttribute.adr && this.newAttribute.city) {
if (this.fieldArray.indexOf(this.newAttribute) === -1) {
this.fieldArray.push(this.newAttribute)
}
}
this.newAttribute = {};//see here
}
Here you are actually emptying the value so the values will be always 0.
But you are already putting the values in the fieldArray, you can easily retrieve the array values by iterating over it and getting the values.
public onAdd(): void {
this.someContact = this.addForm.value;
this.someContact.phoneNumbers = ;
const phno: IPhoneNumber = {
countryCode: this.addForm.value.counrtycode,
number: this.addForm.value.phonenumber,
};
this.someContact.phoneNumbers.push(phno);
this.someContact.addresses = ;
this.fieldArray.forEach(a => {
const addr: IPostalAddress = {
addtype: a.adr,
city: a.city,
};
this.someContact.addresses.push(addr);
})
console.log(this.someContact);
}
I changed type
to addtype
, looks bad naming.
export interface IPostalAddress {
addtype: string;
city: string;
}
Demo
Note: as you are not dealing with the forms you can remove formControlName="adrType"
As addresstype is array and your will not be able to get it easily,
addFieldValue() {
if (this.newAttribute.adr && this.newAttribute.city) {
if (this.fieldArray.indexOf(this.newAttribute) === -1) {
this.fieldArray.push(this.newAttribute)
}
}
this.newAttribute = {};//see here
}
Here you are actually emptying the value so the values will be always 0.
But you are already putting the values in the fieldArray, you can easily retrieve the array values by iterating over it and getting the values.
public onAdd(): void {
this.someContact = this.addForm.value;
this.someContact.phoneNumbers = ;
const phno: IPhoneNumber = {
countryCode: this.addForm.value.counrtycode,
number: this.addForm.value.phonenumber,
};
this.someContact.phoneNumbers.push(phno);
this.someContact.addresses = ;
this.fieldArray.forEach(a => {
const addr: IPostalAddress = {
addtype: a.adr,
city: a.city,
};
this.someContact.addresses.push(addr);
})
console.log(this.someContact);
}
I changed type
to addtype
, looks bad naming.
export interface IPostalAddress {
addtype: string;
city: string;
}
Demo
Note: as you are not dealing with the forms you can remove formControlName="adrType"
answered Dec 31 '18 at 4:29
Just codeJust code
10.4k53066
10.4k53066
1
Thanks for answer and also for your valuable explanation regarding my issue.
– Empty_Soul
Dec 31 '18 at 4:33
add a comment |
1
Thanks for answer and also for your valuable explanation regarding my issue.
– Empty_Soul
Dec 31 '18 at 4:33
1
1
Thanks for answer and also for your valuable explanation regarding my issue.
– Empty_Soul
Dec 31 '18 at 4:33
Thanks for answer and also for your valuable explanation regarding my issue.
– Empty_Soul
Dec 31 '18 at 4:33
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%2f53983501%2fadding-dynamically-added-field-values-along-with-form-values-in-angular%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
which 2 fields are you talking about? addresses are the array.
– Just code
Dec 31 '18 at 4:19
Just fill all
input fields
and also thedynamic fields
and hit theSave
button then see theconsole
, Then you can understand my issue.– Empty_Soul
Dec 31 '18 at 4:25