Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
fix(ngShow): Add/remove ng-hide class instead of ng-show class
Browse files Browse the repository at this point in the history
Closes #521
  • Loading branch information
bgourlie authored and mhevery committed Feb 11, 2014
1 parent aabaa98 commit 0b88d2e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
6 changes: 2 additions & 4 deletions lib/directive/ng_show_hide.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ class NgHideDirective {
selector: '[ng-show]',
map: const {'ng-show': '=>show'})
class NgShowDirective {
static String NG_SHOW_CLASS = 'ng-show';

final dom.Element element;

NgShowDirective(this.element);

set show(value) {
if (toBool(value)) {
element.classes.add(NG_SHOW_CLASS);
element.classes.remove(NgHideDirective.NG_HIDE_CLASS);
} else {
element.classes.remove(NG_SHOW_CLASS);
element.classes.add(NgHideDirective.NG_HIDE_CLASS);
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions test/core_dom/ng_mustache_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,39 +86,39 @@ main() {

beforeEach(inject((TestBed tb) => _ = tb));

it('should add/remove ng-show class', () {
it('should add/remove ng-hide class', () {
var element = _.compile('<div ng-show="isVisible"></div>');

expect(element).not.toHaveClass('ng-show');
expect(element).not.toHaveClass('ng-hide');

_.rootScope.$apply(() {
_.rootScope['isVisible'] = true;
});
expect(element).toHaveClass('ng-show');
expect(element).not.toHaveClass('ng-hide');

_.rootScope.$apply(() {
_.rootScope['isVisible'] = false;
});
expect(element).not.toHaveClass('ng-show');
expect(element).toHaveClass('ng-hide');
});

it('should work together with ng-class', () {
var element = _.compile('<div ng-class="currentCls" ng-show="isVisible"></div>');

expect(element).not.toHaveClass('active');
expect(element).not.toHaveClass('ng-show');
expect(element).not.toHaveClass('ng-hide');

_.rootScope.$apply(() {
_.rootScope['currentCls'] = 'active';
});
expect(element).toHaveClass('active');
expect(element).not.toHaveClass('ng-show');
expect(element).toHaveClass('ng-hide');

_.rootScope.$apply(() {
_.rootScope['isVisible'] = true;
});
expect(element).toHaveClass('active');
expect(element).toHaveClass('ng-show');
expect(element).not.toHaveClass('ng-hide');
});
});

Expand Down
21 changes: 21 additions & 0 deletions test/directive/ng_show_hide_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,25 @@ main() {
expect(_.rootElement).not.toHaveClass('ng-hide');
});
});

describe('NgShow', () {
TestBed _;
beforeEach(inject((TestBed tb) => _ = tb));

it('should add/remove ng-hide class', () {
_.compile('<div ng-show="isShown"></div>');

expect(_.rootElement).not.toHaveClass('ng-hide');

_.rootScope.$apply(() {
_.rootScope['isShown'] = true;
});
expect(_.rootElement).not.toHaveClass('ng-hide');

_.rootScope.$apply(() {
_.rootScope['isShown'] = false;
});
expect(_.rootElement).toHaveClass('ng-hide');
});
});
}

0 comments on commit 0b88d2e

Please sign in to comment.