angular_analyzer_plugin icon indicating copy to clipboard operation
angular_analyzer_plugin copied to clipboard

Can put ngModel on a li?

Open MichaelRFairhurst opened this issue 8 years ago • 2 comments

This passes our analyzer, and, almost certainly shouldn't:

  <li [(ngModel)]="x">...<li>

Seems like anything can have ngModel.

As a short term solution, we could make a whitelist (or even a blacklist) of elements where an ngModel can/cannot go.

I have a feeling that the reason why ngModel can't go on a li is that ngModel uses like @HostAttribute or something. In that case, rather than use a whitelist/blacklist, we can check that the attribute its used on has the targeted attribute.

This is actually a pretty big deal, would make a big case for validating these next-level annotations in angular, which I believe are in the cheatsheet, as unsupported.

MichaelRFairhurst avatar Jan 19 '17 22:01 MichaelRFairhurst

ngModel can go on any element that is either a native input element or where a component or directive is applied that implements ControlValueAccessor

zoechi avatar Jan 20 '17 08:01 zoechi

See also https://github.com/dart-lang/angular2/blob/1b71b61f73f43adcede21470c62e943bed635f69/lib/src/common/forms/directives/ng_model.dart#L76 where NG_VALUE_ACCESSOR is the only non-optional dependency

ControlValueAccessors are registered with NG_VALUE_ACCESSOR (see https://github.com/dart-lang/angular2/blob/164b20a4cd06a1953efcc3ce15d302b31557570e/lib/src/common/forms/directives/default_value_accessor.dart#L8 for an example)

zoechi avatar Jan 20 '17 08:01 zoechi