angular icon indicating copy to clipboard operation
angular copied to clipboard

Can't inject InputElement

Open alorenzen opened this issue 7 years ago • 2 comments

In angular_forms, we have a number of directives that only match an InputElement. However, because of limitations of the DI system, we can only inject a HtmlElement and cast to InputElement. Otherwise, we get No provider found for InputElement error.

Example:

@Directive(selector: `input[ngModel]`)
class MyInputModel {
  final InputElement _element;

  MyInputModel.fails(this._element); // This fails!!

  MyInputModel.works(HtmlElement element) 
      : _element = element as InputElement; // This works!
}

alorenzen avatar Apr 10 '18 18:04 alorenzen

To clarify, this would be a new issue - we would treat any subclass of Element as valid.

matanlurey avatar Apr 10 '18 23:04 matanlurey

To clarify further, we either only want to do this for injection or make additional changes to "fix" queries too. Queries are trickier, because we currently don't store elements as anything but Element or HtmlElement. For example, to query InputElement we would need the (static) type to be of InputElement.

matanlurey avatar Jul 07 '18 06:07 matanlurey