1

I'm using Angular 6 and Bootstrap 4. I have this Bootstrap button group:

<div class="btn-group btn-group-toggle" data-toggle="buttons">
    <label class="btn btn-secondary">
        <input type="radio" [(ngModel)]="usecase" name="options" id="option1" [value]="customer"> Kundenzuordnung
    </label>
    <label class="btn btn-secondary">
        <input type="radio" [(ngModel)]="usecase" name="options" id="option2" [value]="stock"> Lagerware
    </label>
    <label class="btn btn-secondary">
        <input type="radio" [(ngModel)]="usecase" name="options" id="option3" [value]="internalUse"> Interne Verwendung
    </label>
</div>

I want a function to be called when a button is selected and I have tried all of the following methods/properties below:

  • (click)
  • onclick
  • onkeydown
  • ng-change
  • (ngModelChange)
  • left out value field

How can I call my function formChange(0) when the user selects a button?

7
  • What another option ? Commented May 7, 2018 at 21:43
  • ? i dont understand your question Commented May 7, 2018 at 21:45
  • You said "how can i call my function formChange(0), when the user selects another option". What another option? Commented May 7, 2018 at 21:48
  • (ngModelChange)="myFunction($event)" should work. Commented May 7, 2018 at 21:52
  • nope, it doesn't :/ Commented May 8, 2018 at 9:20

2 Answers 2

4

it was so easy... i had to add the (click) function to the label, not to the input.

Sign up to request clarification or add additional context in comments.

Comments

1

Try this one , I think this will work.

 <form #form="ngForm" (ngSubmit)="logForm(form.value)">

    <div class="btn-group btn-group-toggle" data-toggle="buttons">
        <label class="btn btn-secondary">
            <input type="radio" name="options" id="option1" value="customer" ngModel> Kundenzuordnung
        </label>
        <label class="btn btn-secondary">
            <input type="radio" name="options" id="option2" value="stock" ngModel> Lagerware
        </label>
        <label class="btn btn-secondary">
            <input type="radio" name="options" id="option3" value="internalUse" ngModel> Interne Verwendung
        </label>
    </div>

 </form>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.