angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

ng-enabled

Open cricardol opened this issue 14 years ago • 106 comments

Should this attribute be created in a future release?

cricardol avatar Aug 10 '12 14:08 cricardol

+1

marcmenges avatar Jan 21 '14 21:01 marcmenges

:+1:

kevin-smets avatar Jan 21 '14 22:01 kevin-smets

+1 look someone already did the work too: https://github.com/angular/angular.js/pull/4240

BlueRaja avatar Jan 22 '14 00:01 BlueRaja

:+1:

luisrudge avatar Jan 22 '14 01:01 luisrudge

+2 ;)

pawelszymanski avatar Jan 22 '14 22:01 pawelszymanski

+3!

MA3STR0 avatar Feb 07 '14 09:02 MA3STR0

+4

pencilcheck avatar Feb 08 '14 06:02 pencilcheck

+1

ng-disabled="!shouldBeEnabled"

Not fun. Lets get this added. There are other examples of both sides of the boolean being part of Angular. The current situation only leads to avoidable API confusion which seems to be one of the only gripes anyone has about Angular. Some examples:

• ngHide/ngShow • $even, $odd • !$first && !$last === $middle

johnculviner avatar Feb 15 '14 20:02 johnculviner

+1 --1 for the core Angular devs.

reergymerej avatar Feb 17 '14 03:02 reergymerej

I think ng-enabled doesn't make much sense. Even though the implementation adds few lines only, it increases the size unnecessarily.

This is just a thought:

When we need to really use ng-enabled over ng-disabled ? In case of why we need ng-hide and ng-show, the reason I can think would be: they're toggling CSS styles. It means, the display property accept multiple values to show and hide elements. So ng-show is required if the element is hidden by CSS already.

But in case of ng-disabled, @andershessellund already said, there's no attribute called enabled; and I don't think that we would be able to disable some elements from CSS already. So if we cannot disable any element before the element is compiled in Angular, what's the real need of ng-enabled ?

Somebody please correct if I am completely wrong. May be I'm missing something here.

shidhincr avatar Feb 17 '14 04:02 shidhincr

@shidhincr It's about code readability and API consistency.

As @adz said earlier in this post:

" It sometimes reads better, just like the show/hide variants, by avoiding double negatives:

    <button ng-enabled='loaded && product.available'/>

Vs:

    <button ng-disabled='!(loaded && product.available)'/> '''

"

Also, you can look at AngularJS directives as an abstraction layer over HTML that replaces attributes like "disabled". If that abstraction layer offers me something to be "ng-disabled", I don't care if there are no lower level HTML attribute called "enabled" that prevents me from also using "ng-enabled". Just make the API consistent is what I'm asking.

I have no idea if this point idea about "abstraction layer" really fits with the intentions of the AngularJS project. Still, I want "ng-enabled" for consistency.

edit: syntax highlighting

yngvark avatar Feb 17 '14 07:02 yngvark

@shidhincr ngshow / nghide are exact inverse of each other. Compare https://github.com/angular/angular.js/blob/1fb47e08a0eed4d4ec4638367edb08dfbcce465b/src/ng/directive/ngShowHide.js#L154-L160

var ngShowDirective = ['$animate', function($animate) {
  return function(scope, element, attr) {
    scope.$watch(attr.ngShow, function ngShowWatchAction(value){
      $animate[toBoolean(value) ? 'removeClass' : 'addClass'](element, 'ng-hide');
    });
  };
}];

vs.

var ngHideDirective = ['$animate', function($animate) {
  return function(scope, element, attr) {
    scope.$watch(attr.ngHide, function ngHideWatchAction(value){
      $animate[toBoolean(value) ? 'addClass' : 'removeClass'](element, 'ng-hide');
    });
  };
}];

So having either with the ! of another would be sufficient and one of them is functionally redundant but useful for developer ease.

basarat avatar Feb 17 '14 07:02 basarat

Guys, stop.

This isn't a public debate. The core team isn't interested. They asked for a pull request and the milestone where they were going to discuss it has come and gone.

The fact is that at this point they have literally dozens of pull requests for fixing bugs that haven't made it in. They have too much on their plates as is.

At the time I wrote the pull request for this feature, it wasn't because I thought it was necessary, but because I thought I was helping as a result of the "PRs Welcome" tag the issue had. I can see now that merging pull or closing pull requests from the public takes a very, very long time, so they can only do a few a week. Look at how many they have in the backlog!

There is no need to +1 this issue, I promise that the team knows that some people want it. It adds fewer than 5 lines of code, and the way I wrote it would allow them to add inverses for other predicate attributes declaratively. I promise, they either know all this and don't care, or they don't know after 5 months and adding comments to this issue is clearly not helping.

Please, please stop. If you want to help make angular better, try finding and helping close erroneous issues. If you just want to have an opinion on something, try something a little more substantive.

cqr avatar Feb 17 '14 13:02 cqr

+1

ivan-saorin avatar Mar 07 '14 22:03 ivan-saorin

+1

nitso avatar Apr 11 '14 12:04 nitso

+1

AndreiZaman avatar Jun 13 '14 13:06 AndreiZaman

+1

HardieBoeve avatar Jun 13 '14 13:06 HardieBoeve

Everyone I've worked with downright expects this feature and considers it a quirk that it's missing. Nobody I talked to cares about the lack of an "enabled" attribute in HTML. IMO this screams poor developer-usability.

+1

OlmoAcerta avatar Jul 01 '14 11:07 OlmoAcerta

+1 clearly

Chexpir avatar Jul 07 '14 09:07 Chexpir

+1 for avoiding double negatives

adamkdean avatar Jul 07 '14 10:07 adamkdean