0

New to Angular and Typescript, trying to set a control's attribute using a method on my Component. Is it possible to send the Button control itself as an argument?

<input type="button" id="Button1" data-something="{{ GetSomething(this) }}">

And my method on my Component:

GetSomething(sender) {

    //do something with sender being the Button

    console.log(sender.id);

    return "garbage";
}
2
  • Why would you want to do this? There are other ways to set classes using *ngClass or [class.foo] and the button element wouldn't really tell you anything. Commented Apr 17, 2018 at 17:15
  • Got it, assume class is a data- attribute instead. I used class just for this example. Will edit. Commented Apr 17, 2018 at 17:22

1 Answer 1

2

If by this, you meant the HTMLElement then the following might work: <input type="button" id="Buttong1" #someBtn class="{{ GetButtonClass(someBtn)}}">

Or read up on ngClass or Class binding:

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.