diff options
Diffstat (limited to 'src/directive/ngShowHide.js')
| -rw-r--r-- | src/directive/ngShowHide.js | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/directive/ngShowHide.js b/src/directive/ngShowHide.js new file mode 100644 index 00000000..0060ec80 --- /dev/null +++ b/src/directive/ngShowHide.js @@ -0,0 +1,80 @@ +'use strict'; + +/** + * @ngdoc directive + * @name angular.module.ng.$compileProvider.directive.ng:show + * + * @description + * The `ng:show` and `ng:hide` directives show or hide a portion of the DOM tree (HTML) + * conditionally. + * + * @element ANY + * @param {expression} expression If the {@link guide/dev_guide.expressions expression} is truthy + * then the element is shown or hidden respectively. + * + * @example + <doc:example> + <doc:source> + Click me: <input type="checkbox" ng:model="checked"><br/> + Show: <span ng:show="checked">I show up when your checkbox is checked.</span> <br/> + Hide: <span ng:hide="checked">I hide when your checkbox is checked.</span> + </doc:source> + <doc:scenario> + it('should check ng:show / ng:hide', function() { + expect(element('.doc-example-live span:first:hidden').count()).toEqual(1); + expect(element('.doc-example-live span:last:visible').count()).toEqual(1); + + input('checked').check(); + + expect(element('.doc-example-live span:first:visible').count()).toEqual(1); + expect(element('.doc-example-live span:last:hidden').count()).toEqual(1); + }); + </doc:scenario> + </doc:example> + */ +//TODO(misko): refactor to remove element from the DOM +var ngShowDirective = ngDirective(function(scope, element, attr){ + scope.$watch(attr.ngShow, function(value){ + element.css('display', toBoolean(value) ? '' : 'none'); + }); +}); + + +/** + * @ngdoc directive + * @name angular.module.ng.$compileProvider.directive.ng:hide + * + * @description + * The `ng:hide` and `ng:show` directives hide or show a portion + * of the HTML conditionally. + * + * @element ANY + * @param {expression} expression If the {@link guide/dev_guide.expressions expression} truthy then + * the element is shown or hidden respectively. + * + * @example + <doc:example> + <doc:source> + Click me: <input type="checkbox" ng:model="checked"><br/> + Show: <span ng:show="checked">I show up when you checkbox is checked?</span> <br/> + Hide: <span ng:hide="checked">I hide when you checkbox is checked?</span> + </doc:source> + <doc:scenario> + it('should check ng:show / ng:hide', function() { + expect(element('.doc-example-live span:first:hidden').count()).toEqual(1); + expect(element('.doc-example-live span:last:visible').count()).toEqual(1); + + input('checked').check(); + + expect(element('.doc-example-live span:first:visible').count()).toEqual(1); + expect(element('.doc-example-live span:last:hidden').count()).toEqual(1); + }); + </doc:scenario> + </doc:example> + */ +//TODO(misko): refactor to remove element from the DOM +var ngHideDirective = ngDirective(function(scope, element, attr){ + scope.$watch(attr.ngHide, function(value){ + element.css('display', toBoolean(value) ? 'none' : ''); + }); +}); |
