-
Notifications
You must be signed in to change notification settings - Fork 27.4k
ngAttr added attributes don't trigger directives #12363
Comments
This is one of those difficult things --- unfortunately, we don't have a good way to trigger compilation when the DOM changes in this way. Attempting to do so would massively harm performance. To add to this, there's also no way to "trigger" one particular directive, all you can do is compile an entire chunk of DOM. You could explicitly recompile the chunk of DOM you want to, but there isn't really a good way to do this. |
oops, didn't mean to close that, maybe someone else will have something to say about it. |
Agree with @caitp that it would be very hard to support. I would suggest that we focus on the original issue of the conditional |
This is easy to work around by means of: |
All makes sense.
|
When the min/max attributes are empty (i.e. `attrs.min/max === ''`), there should be no min/max validation applied (i.e. all values should be valid wrt min/max). This works correctly for `input[number]`, but not for date input family (`input[date/datetime-local/time/week/month]`). In the case on `input[number]`, an empty string for `attrs.min/max` is translated to `undefined` for `minVal/maxVal` and a check for `isUndefined(minVal/maxVal)` ensures that no min/max validation takes place. For the data input family, an empty string for `attrs.min/max` is translated to `NaN` (by `parseDate()`), so an additional check (for `isNaN(minVal/maxVal)`) is required. Fixes angular#12363
When the min/max attributes are empty (i.e. `attrs.min/max === ''`), there should be no min/max validation applied (i.e. all values should be valid wrt min/max). This works correctly for `input[number]`, but not for date input family (`input[date/datetime-local/time/week/month]`). In the case on `input[number]`, an empty string for `attrs.min/max` is translated to `undefined` for `minVal/maxVal` and a check for `isUndefined(minVal/maxVal)` ensures that no min/max validation takes place. For the data input family, an empty string for `attrs.min/max` is translated to `NaN` (by `parseDate()`), so an additional check (for `isNaN(minVal/maxVal)`) is required. Fixes angular#12363
This may be by design, but I thought I'd bring it up.
Since
ngAttr
-prefixed attributes are interpolated with allOrNothing, an attribute may or may not be present initially. If the expression is defined on the first evaluation, it looks like the resulting attribute will trigger directives. However, if the expression is initially undefined, when it later becomes defined the attribute that is added will not cause any directives to be applied to the element.My use case is this: I'm using
ng-attr-min
andng-attr-max
on aninput[type=date]
with something likeng-attr-min="{{minDate | date:'yyyy-MM-dd'}}"
. IfminDate
is undefined, I don't want there to be any min validation. WhenminDate
becomes defined, the min attribute is properly set but themin
directive is not applied retroactively, therefore I don't get my angular min validation.The alternatives are
ngMin
, but this doesn't set themin
attribute and on Chrome the datepicker won't be properly restricted.min
directly (e.g.min="{{minDate | date:'yyyy-MM-dd'}}"
), but whenminDate
is undefined, this leaves a danglingmin
attribute with no value which incorrectly makes any value invalid (this might be a bug).The text was updated successfully, but these errors were encountered: