-
Notifications
You must be signed in to change notification settings - Fork 27.4k
ngAttr for boolean attributes #2111
Comments
I have a use-case that is not related to autofocus. I cannot find anything beyond this here issue which didn't live long. I'm trying to prove Angular can work seamlessly with native Web Components, and am hitting this issue. For several components, boolean attributes make a lot of sense, and as far as I can tell Angular has special directives in place for every one of them. Surely a global directive like Thoughts? |
Absolutely true! But neither of those have landed, so until that point I On 29 July 2014 23:00, Caitlin Potter notifications@github.com wrote:
|
well #4269 isn't going to land, like I said it's been suggested that someone publish it as an external module, but I don't have the cycles to maintain another module right now, so someone else is welcome to take the code and run with it. As for the other one, I'm hoping to get that one in either this week or next week, once we decide on a syntax that makes people happy. |
this issue was closed ages ago so there isn't much point in re-opening it, but you could always open another one asking for this. |
Fair enough. Was hoping there was a way around this with code that's in On 29 July 2014 23:17, Caitlin Potter notifications@github.com wrote:
|
you can write a directive like this: {
restrict: 'A',
link: ($scope,$element,$attr) => {
$scope.$watch($attr.ifAttr, val => {
Object.keys(val).forEach(key => {
if (val[key])
$element.attr(key,'');
else
$element.removeAttr(key);
});
});
};
} and use it like ngClass or ngStyle: |
I came across #698 again and wonder if the new ngAttr support could help with autofocus if it had special behavior for boolean values. Perhaps something like:
could cause the autofocus attribute to be added (with a value of
value
) whenvalue
is truthy, and would cause the attribute to be removed whenvalue
is falsey (rather than giving it a value of "false").The text was updated successfully, but these errors were encountered: