someone
someone

Reputation: 575

How we can have events in one form with angular 2

All I want is one form which has two different buttons with different actions behind. I was wondering in every angular 2 component we can have only one onSubmit to call service. how can I have two? and how can I tell angular which buttons is associate to which service call. when there is one button every thing is Ok but not with two buttons. this is my onSubmit code:

onSubmit() {

this.service.generatePhone(this.data)
    .subscribe(
    () => {
        this.success = true;
    },
    (error) => {

    },

I want another onSubmit to call service.updatePhone. and in my shortened html file:

<div class="form-signin">

    <form #myForm="ngForm"  (ngSubmit)="onSubmit()">
        <div class="form-group">
            <p class="text-left">your phone number </p>
        </div>
        <button type="submit" >
           generate
        </button>
        <br/>
    </form>
</div>

I want another

 <button type="submit" >update </button>

Upvotes: 0

Views: 23

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657238

<button type="button" (click)="doSomething()">

Upvotes: 1

Related Questions