Passing ngSubmit as reference Angular
Is it possible to pass the ngSubmit function as a parameter?
I created a component that receives an Id and the name of the ngSubmit function, but how do I put this parameter on the template?
I have a component called validation-form
validation-form.component.html
<form [id]="formId" method="post" novalidate [(ngSubmit)]="">
<ng-content></ng-content>
</form>
My validation-form.component.ts has
@Input() formId: string;
@Input() submit: string;
I pass this values like this
<validation-form formId="ResetPasswordForm" submit="resetPassword()">
</validation-form>
I want to put the value of @Input() submit: string; to to the (ngSubmit). How can i do this?
angular typescript angularjs-directive angular7
add a comment |
Is it possible to pass the ngSubmit function as a parameter?
I created a component that receives an Id and the name of the ngSubmit function, but how do I put this parameter on the template?
I have a component called validation-form
validation-form.component.html
<form [id]="formId" method="post" novalidate [(ngSubmit)]="">
<ng-content></ng-content>
</form>
My validation-form.component.ts has
@Input() formId: string;
@Input() submit: string;
I pass this values like this
<validation-form formId="ResetPasswordForm" submit="resetPassword()">
</validation-form>
I want to put the value of @Input() submit: string; to to the (ngSubmit). How can i do this?
angular typescript angularjs-directive angular7
You will have to pass the appropriate function as a reference and not by method name (i.e.<validation-form ... [submit]="resetPassword">
). The function will not be accessible by name outside of your component that is using<validation-form>
.
– Daniel W Strimpel
Nov 14 '18 at 20:44
I'm starting to study angular, so if you could give me more details it would be great. Using [submit]="resetPassword" will get the reference of the method? And how do I use this reference on the ngSubmit? Thx for answering XD
– Testador
Nov 14 '18 at 20:54
2
I fail to see the point of that component, since it doesn't do anything other than a standard form already does. But submit shouldn't be an input. It should be an output. Your validation form component should emit an event to its parent when the form is being submitted.
– JB Nizet
Nov 14 '18 at 20:55
I created this component because i'm using a jquery validation lib that already have all the validation and messages I need.
– Testador
Nov 16 '18 at 0:48
add a comment |
Is it possible to pass the ngSubmit function as a parameter?
I created a component that receives an Id and the name of the ngSubmit function, but how do I put this parameter on the template?
I have a component called validation-form
validation-form.component.html
<form [id]="formId" method="post" novalidate [(ngSubmit)]="">
<ng-content></ng-content>
</form>
My validation-form.component.ts has
@Input() formId: string;
@Input() submit: string;
I pass this values like this
<validation-form formId="ResetPasswordForm" submit="resetPassword()">
</validation-form>
I want to put the value of @Input() submit: string; to to the (ngSubmit). How can i do this?
angular typescript angularjs-directive angular7
Is it possible to pass the ngSubmit function as a parameter?
I created a component that receives an Id and the name of the ngSubmit function, but how do I put this parameter on the template?
I have a component called validation-form
validation-form.component.html
<form [id]="formId" method="post" novalidate [(ngSubmit)]="">
<ng-content></ng-content>
</form>
My validation-form.component.ts has
@Input() formId: string;
@Input() submit: string;
I pass this values like this
<validation-form formId="ResetPasswordForm" submit="resetPassword()">
</validation-form>
I want to put the value of @Input() submit: string; to to the (ngSubmit). How can i do this?
angular typescript angularjs-directive angular7
angular typescript angularjs-directive angular7
asked Nov 14 '18 at 20:27
TestadorTestador
264
264
You will have to pass the appropriate function as a reference and not by method name (i.e.<validation-form ... [submit]="resetPassword">
). The function will not be accessible by name outside of your component that is using<validation-form>
.
– Daniel W Strimpel
Nov 14 '18 at 20:44
I'm starting to study angular, so if you could give me more details it would be great. Using [submit]="resetPassword" will get the reference of the method? And how do I use this reference on the ngSubmit? Thx for answering XD
– Testador
Nov 14 '18 at 20:54
2
I fail to see the point of that component, since it doesn't do anything other than a standard form already does. But submit shouldn't be an input. It should be an output. Your validation form component should emit an event to its parent when the form is being submitted.
– JB Nizet
Nov 14 '18 at 20:55
I created this component because i'm using a jquery validation lib that already have all the validation and messages I need.
– Testador
Nov 16 '18 at 0:48
add a comment |
You will have to pass the appropriate function as a reference and not by method name (i.e.<validation-form ... [submit]="resetPassword">
). The function will not be accessible by name outside of your component that is using<validation-form>
.
– Daniel W Strimpel
Nov 14 '18 at 20:44
I'm starting to study angular, so if you could give me more details it would be great. Using [submit]="resetPassword" will get the reference of the method? And how do I use this reference on the ngSubmit? Thx for answering XD
– Testador
Nov 14 '18 at 20:54
2
I fail to see the point of that component, since it doesn't do anything other than a standard form already does. But submit shouldn't be an input. It should be an output. Your validation form component should emit an event to its parent when the form is being submitted.
– JB Nizet
Nov 14 '18 at 20:55
I created this component because i'm using a jquery validation lib that already have all the validation and messages I need.
– Testador
Nov 16 '18 at 0:48
You will have to pass the appropriate function as a reference and not by method name (i.e.
<validation-form ... [submit]="resetPassword">
). The function will not be accessible by name outside of your component that is using <validation-form>
.– Daniel W Strimpel
Nov 14 '18 at 20:44
You will have to pass the appropriate function as a reference and not by method name (i.e.
<validation-form ... [submit]="resetPassword">
). The function will not be accessible by name outside of your component that is using <validation-form>
.– Daniel W Strimpel
Nov 14 '18 at 20:44
I'm starting to study angular, so if you could give me more details it would be great. Using [submit]="resetPassword" will get the reference of the method? And how do I use this reference on the ngSubmit? Thx for answering XD
– Testador
Nov 14 '18 at 20:54
I'm starting to study angular, so if you could give me more details it would be great. Using [submit]="resetPassword" will get the reference of the method? And how do I use this reference on the ngSubmit? Thx for answering XD
– Testador
Nov 14 '18 at 20:54
2
2
I fail to see the point of that component, since it doesn't do anything other than a standard form already does. But submit shouldn't be an input. It should be an output. Your validation form component should emit an event to its parent when the form is being submitted.
– JB Nizet
Nov 14 '18 at 20:55
I fail to see the point of that component, since it doesn't do anything other than a standard form already does. But submit shouldn't be an input. It should be an output. Your validation form component should emit an event to its parent when the form is being submitted.
– JB Nizet
Nov 14 '18 at 20:55
I created this component because i'm using a jquery validation lib that already have all the validation and messages I need.
– Testador
Nov 16 '18 at 0:48
I created this component because i'm using a jquery validation lib that already have all the validation and messages I need.
– Testador
Nov 16 '18 at 0:48
add a comment |
1 Answer
1
active
oldest
votes
It looks like you want to handle the validation
or submission
on parent component rather than child component validation-form
.
To achieve this, you can use @Output
decorator. It will propagate event from child to parent. Here is the code which can help you to achieve the same.
validation-form.component.ts
@Input() formId: string;
@Input() submit: string;
@Output() submit = new EventEmitter();
public submit()
this.validate.emit(this.formId); //<-- you can pass the object if you need more info to pass.
validation-form.component.html
<form [id]="formId" method="post" novalidate (ngSubmit)="submit()">
<ng-content></ng-content>
</form>
Parent Component.html
<validation-form formId="ResetPasswordForm" (submit)="resetPassword($event)">
</validation-form>
Parent Component.ts
public resetPassword(formId)
console.log("Form Id ", formId);
@Input() submit: string
This line is no logner needed, right?
– Testador
Nov 16 '18 at 0:53
Exactly, you can remove that.
– Sunil Singh
Nov 16 '18 at 3:39
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%2f53308264%2fpassing-ngsubmit-as-reference-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
It looks like you want to handle the validation
or submission
on parent component rather than child component validation-form
.
To achieve this, you can use @Output
decorator. It will propagate event from child to parent. Here is the code which can help you to achieve the same.
validation-form.component.ts
@Input() formId: string;
@Input() submit: string;
@Output() submit = new EventEmitter();
public submit()
this.validate.emit(this.formId); //<-- you can pass the object if you need more info to pass.
validation-form.component.html
<form [id]="formId" method="post" novalidate (ngSubmit)="submit()">
<ng-content></ng-content>
</form>
Parent Component.html
<validation-form formId="ResetPasswordForm" (submit)="resetPassword($event)">
</validation-form>
Parent Component.ts
public resetPassword(formId)
console.log("Form Id ", formId);
@Input() submit: string
This line is no logner needed, right?
– Testador
Nov 16 '18 at 0:53
Exactly, you can remove that.
– Sunil Singh
Nov 16 '18 at 3:39
add a comment |
It looks like you want to handle the validation
or submission
on parent component rather than child component validation-form
.
To achieve this, you can use @Output
decorator. It will propagate event from child to parent. Here is the code which can help you to achieve the same.
validation-form.component.ts
@Input() formId: string;
@Input() submit: string;
@Output() submit = new EventEmitter();
public submit()
this.validate.emit(this.formId); //<-- you can pass the object if you need more info to pass.
validation-form.component.html
<form [id]="formId" method="post" novalidate (ngSubmit)="submit()">
<ng-content></ng-content>
</form>
Parent Component.html
<validation-form formId="ResetPasswordForm" (submit)="resetPassword($event)">
</validation-form>
Parent Component.ts
public resetPassword(formId)
console.log("Form Id ", formId);
@Input() submit: string
This line is no logner needed, right?
– Testador
Nov 16 '18 at 0:53
Exactly, you can remove that.
– Sunil Singh
Nov 16 '18 at 3:39
add a comment |
It looks like you want to handle the validation
or submission
on parent component rather than child component validation-form
.
To achieve this, you can use @Output
decorator. It will propagate event from child to parent. Here is the code which can help you to achieve the same.
validation-form.component.ts
@Input() formId: string;
@Input() submit: string;
@Output() submit = new EventEmitter();
public submit()
this.validate.emit(this.formId); //<-- you can pass the object if you need more info to pass.
validation-form.component.html
<form [id]="formId" method="post" novalidate (ngSubmit)="submit()">
<ng-content></ng-content>
</form>
Parent Component.html
<validation-form formId="ResetPasswordForm" (submit)="resetPassword($event)">
</validation-form>
Parent Component.ts
public resetPassword(formId)
console.log("Form Id ", formId);
It looks like you want to handle the validation
or submission
on parent component rather than child component validation-form
.
To achieve this, you can use @Output
decorator. It will propagate event from child to parent. Here is the code which can help you to achieve the same.
validation-form.component.ts
@Input() formId: string;
@Input() submit: string;
@Output() submit = new EventEmitter();
public submit()
this.validate.emit(this.formId); //<-- you can pass the object if you need more info to pass.
validation-form.component.html
<form [id]="formId" method="post" novalidate (ngSubmit)="submit()">
<ng-content></ng-content>
</form>
Parent Component.html
<validation-form formId="ResetPasswordForm" (submit)="resetPassword($event)">
</validation-form>
Parent Component.ts
public resetPassword(formId)
console.log("Form Id ", formId);
answered Nov 15 '18 at 7:55
Sunil SinghSunil Singh
6,3572627
6,3572627
@Input() submit: string
This line is no logner needed, right?
– Testador
Nov 16 '18 at 0:53
Exactly, you can remove that.
– Sunil Singh
Nov 16 '18 at 3:39
add a comment |
@Input() submit: string
This line is no logner needed, right?
– Testador
Nov 16 '18 at 0:53
Exactly, you can remove that.
– Sunil Singh
Nov 16 '18 at 3:39
@Input() submit: string
This line is no logner needed, right?– Testador
Nov 16 '18 at 0:53
@Input() submit: string
This line is no logner needed, right?– Testador
Nov 16 '18 at 0:53
Exactly, you can remove that.
– Sunil Singh
Nov 16 '18 at 3:39
Exactly, you can remove that.
– Sunil Singh
Nov 16 '18 at 3:39
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%2f53308264%2fpassing-ngsubmit-as-reference-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
You will have to pass the appropriate function as a reference and not by method name (i.e.
<validation-form ... [submit]="resetPassword">
). The function will not be accessible by name outside of your component that is using<validation-form>
.– Daniel W Strimpel
Nov 14 '18 at 20:44
I'm starting to study angular, so if you could give me more details it would be great. Using [submit]="resetPassword" will get the reference of the method? And how do I use this reference on the ngSubmit? Thx for answering XD
– Testador
Nov 14 '18 at 20:54
2
I fail to see the point of that component, since it doesn't do anything other than a standard form already does. But submit shouldn't be an input. It should be an output. Your validation form component should emit an event to its parent when the form is being submitted.
– JB Nizet
Nov 14 '18 at 20:55
I created this component because i'm using a jquery validation lib that already have all the validation and messages I need.
– Testador
Nov 16 '18 at 0:48