2012-03-08 23:00:38 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc directive
|
2012-06-12 06:49:24 +00:00
|
|
|
* @name ng.directive:ngShow
|
2012-03-08 23:00:38 +00:00
|
|
|
*
|
|
|
|
|
* @description
|
2012-04-06 23:35:17 +00:00
|
|
|
* The `ngShow` and `ngHide` directives show or hide a portion of the DOM tree (HTML)
|
2012-03-08 23:00:38 +00:00
|
|
|
* conditionally.
|
|
|
|
|
*
|
|
|
|
|
* @element ANY
|
2012-05-24 21:49:47 +00:00
|
|
|
* @param {expression} ngShow If the {@link guide/expression expression} is truthy
|
2012-03-08 23:00:38 +00:00
|
|
|
* then the element is shown or hidden respectively.
|
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
<doc:example>
|
|
|
|
|
<doc:source>
|
2012-03-09 08:00:05 +00:00
|
|
|
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>
|
2012-03-08 23:00:38 +00:00
|
|
|
</doc:source>
|
|
|
|
|
<doc:scenario>
|
2012-03-09 08:00:05 +00:00
|
|
|
it('should check ng-show / ng-hide', function() {
|
2012-03-08 23:00:38 +00:00
|
|
|
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){
|
2012-07-06 09:53:40 +00:00
|
|
|
scope.$watch(attr.ngShow, function ngShowWatchAction(value){
|
2012-03-08 23:00:38 +00:00
|
|
|
element.css('display', toBoolean(value) ? '' : 'none');
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @ngdoc directive
|
2012-06-12 06:49:24 +00:00
|
|
|
* @name ng.directive:ngHide
|
2012-03-08 23:00:38 +00:00
|
|
|
*
|
|
|
|
|
* @description
|
2012-11-09 13:44:00 +00:00
|
|
|
* The `ngHide` and `ngShow` directives hide or show a portion of the DOM tree (HTML)
|
|
|
|
|
* conditionally.
|
2012-03-08 23:00:38 +00:00
|
|
|
*
|
|
|
|
|
* @element ANY
|
2012-11-09 13:44:00 +00:00
|
|
|
* @param {expression} ngHide If the {@link guide/expression expression} is truthy then
|
2012-03-08 23:00:38 +00:00
|
|
|
* the element is shown or hidden respectively.
|
|
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
<doc:example>
|
|
|
|
|
<doc:source>
|
2012-03-09 08:00:05 +00:00
|
|
|
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>
|
2012-03-08 23:00:38 +00:00
|
|
|
</doc:source>
|
|
|
|
|
<doc:scenario>
|
2012-03-09 08:00:05 +00:00
|
|
|
it('should check ng-show / ng-hide', function() {
|
2012-03-08 23:00:38 +00:00
|
|
|
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){
|
2012-07-06 09:53:40 +00:00
|
|
|
scope.$watch(attr.ngHide, function ngHideWatchAction(value){
|
2012-03-08 23:00:38 +00:00
|
|
|
element.css('display', toBoolean(value) ? 'none' : '');
|
|
|
|
|
});
|
|
|
|
|
});
|