ng-enabled
Should this attribute be created in a future release?
+1
@chrisrhoden, this is absolutely a public debate because we are making it one. If enough people +1 this thread they will change it. I promise.
+1
+1
+1
+1 for avoiding double negatives
@chrishoden, it adds fewer than 5 lines of code and yet it can't get reviewed by the core team after nearly a year? Angular is either really buggy or they really don't care. Can't wait to see the first "This Pull Request Is Why I Left Angular for NNNN" post.
That isn't nice :(
@zdennis This is not a PR, this is an issue. Stop crying, make a PR.
@caitp, I'm not being mean, just a belated reply to the Feb 17 plea for people to stop. If someone writes a post due to this I would find it comical.
@pawelszmanski, definitely not crying about. Not sure how my response results in whining. It is what is.
So, I'm not going to pretend to have a definitive answer about this, but I think having two options for this introduces some issues.
- If both
ngEnabledandngDisabledare specified for an element, which one wins? Why would anyone do that? that's not important, it would enable them to. We can't have an indeterminate enabled/disabled state! - HTML has no concept of "enabled", for pretty much that exact reason. We only really have a disabled state. I think matching HTML is sensible here.
- Is a
!really that bad? I mean, is it?
So, I'm sure that none of those points are satisfactory for anyone, but these are things to consider. I've asked if we can get some closure on this, but personally I feel like this feature would add more problems than it would solve.
Again, I'm not the one definitively saying no here, this is just my opinion --- I'm happy to (politely) discuss it, though.
Ideally, if both ng-enabled and ng-disabled is present, it should result in an error during compilation. That whould add additional code (bloat).
@caitp re 1.: disabled > enabled, just like exclusions > inclusions in most APIs? That's pretty straightforward and defensive thinking I guess. re 3.:
- yes it is, if you use Coffeescript and you are not get used to this awful syntax ;)
- yes, since it's harder to read and that means it's much harder to understand
- but most importantly yes because thinking about double negation takes unnecessary time
BTW: this made me thinking that in fact that would be nice if $eval would accept some of coffeescript syntax, like and, or, but that's on offtopic.
@caitp Angular has ngShow and ngHide - what happens if both of those are enabled on an element?
I don't know the answer, but the point is any argument for or against having ngEnabled should also apply to ngShow. It doesn't make sense for the developers to be arguing ngEnabled is unnecessary bloat, while simultaneously including ngShow. Either ngEnabled should be added, or ngShow should be depricated. I'd prefer the former.
Also, I don't understand where the argument "HTML doesn't have an enabled attribute" comes from. Angular already extends HTML, so who cares what HTML does or doesn't do?
What happens if you define ngShow and ngHide on the same element? They are exactly the same as these two would be. So the behaviour should be the same imo.
hmm, that's a good point re: ngShow / ngHide, I guess we should revert ngHide ;) But jokes aside, I am not sure that's a kind of API that we should necessarily make more of. I realize that it's convenient, and looks nice declaratively (which is super important), but if we don't have defined rules for how to behave when both are specified, then really we have an indeterminate state, and this is bad
@caitp re 3.: to add a point: Afaik Angular handles undefined values gracefully. So with ng-enabled I could write "ng-enabled='vm.foo()'" and get a fine fallback in case the controller doesn't define foo(). But I cannot negate undefined, so with only ng-disabled at hand I need to write "ng-disabled='!(vm.foo ? vm.foo() : true)'". Is that really bad? IMHO: yes, it is.
ng-hide takes precedence over ng-show: http://plnkr.co/edit/BU5wlx?p=preview
@jamesdaily yes, but this is not by design. We have no code enforcing this behaviour anywhere, it basically comes down to the order $scope watchers are registered, which comes down to the order link functions are evaluated, which comes down to the alphabetical order of the directive names. This system is complete nonsense --- it is consistent, which is good, but it's not "by design", which is bad, because it means that the slightest arbitrary and unrelated change can break this.
So this is not what we really want for ngShow or ngHide, in my opinion. Maybe ngHide should override ngShow, but the override should be explicit rather than implicit.
To go further, "exclude vs include" doesn't really make sense when we're talking about a single boolean property. There's no logic that says "- 1 + 1 === -1", this doesn't really fly. Likewise, "+1 -1 === 1" also doesn't really fly. N'either of these cases really make sense for a boolean value, this ordering only makes logical sense when operating on sets (which we aren't here, in either ngShowHide or ngDisabledEnabled)
@caitp how about priority in directiveDefinitionObject?
I guess it could help in case of two mutually exclusive behaviors / directives, or am I missing something?
no, priority isn't super helpful in this case, it's actually proved to be a pretty inadequate solution for sorting out the order of operations here.
Yes, we want directives to be compiled and linked in a predictable fashion, but this is totally unrelated to what we want for figuring out whether enabled wins over disabled. They're tools which reach that end, but not in a good way, and it's arguably not a great way to solve the predictability problem, either.
I don't think we should rely on directive priority as a way to enforce a policy on "disabled beats enabled" (personal opinion, not representative of anyone else working on angular). (further, directive priority is really no different from the alphabetical ordering thing --- it's just an arbitrary way of sorting directives, and it's got its shared of problems).