1

I want to create a directive (alert-select) that can make some actions when I change the value of a select element

<select alert-select [(ngModel)]="area_id">
    <option value="1">Area 1</option>
    <option value="2">Area 2</option>
</select>

I want (without use (change)) to alert(area_id) the value of the select every time I change it.

1 Answer 1

1

You can add an event listener inside your directive

@HostListener('ngModelChange', ['$event'])
onChange(event) {
  console.log(event);
}

or

@HostListener('change', ['$event'])
onChange(event) {
  console.log(event.target.value);
}

(or both to make it work with or without ngModel)

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

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.