diff options
| author | Jamund Ferguson | 2013-06-27 16:18:00 -0700 | 
|---|---|---|
| committer | Igor Minar | 2013-08-07 15:36:02 -0700 | 
| commit | 66007a4150a84980ae3578a1a6e542880bb7f408 (patch) | |
| tree | 467e8f4b11f449b6028e366d726a639f7bd54f94 /src | |
| parent | 7f14cdeeb531d140b25b10f5eb7d6643cd950210 (diff) | |
| download | angular.js-66007a4150a84980ae3578a1a6e542880bb7f408.tar.bz2 | |
docs(ngClass): updated the example with string, map and array syntax
Closes #3084
Diffstat (limited to 'src')
| -rw-r--r-- | src/ng/directive/ngClass.js | 61 | 
1 files changed, 60 insertions, 1 deletions
| diff --git a/src/ng/directive/ngClass.js b/src/ng/directive/ngClass.js index 38b804b5..db6e7ac8 100644 --- a/src/ng/directive/ngClass.js +++ b/src/ng/directive/ngClass.js @@ -93,7 +93,66 @@ function classDirective(name, selector) {   *   names of the properties whose values are truthy will be added as css classes to the   *   element.   * - * @example + * @example Example that demostrates basic bindings via ngClass directive. +   <example> +     <file name="index.html"> +       <p ng-class="{strike: strike, bold: bold, red: red}">Map Syntax Example</p> +       <input type="checkbox" ng-model="bold"> bold +       <input type="checkbox" ng-model="strike"> strike +       <input type="checkbox" ng-model="red"> red +       <hr> +       <p ng-class="style">Using String Syntax</p> +       <input type="text" ng-model="style" placeholder="Type: bold strike red"> +       <hr> +       <p ng-class="[style1, style2, style3]">Using Array Syntax</p> +       <input ng-model="style1" placeholder="Type: bold"><br> +       <input ng-model="style2" placeholder="Type: strike"><br> +       <input ng-model="style3" placeholder="Type: red"><br> +     </file> +     <file name="style.css"> +       .strike { +         text-decoration: line-through; +       } +       .bold { +           font-weight: bold; +       } +       .red { +           color: red; +       } +     </file> +     <file name="scenario.js"> +       it('should let you toggle the class', function() { + +         expect(element('.doc-example-live p:first').prop('className')).not().toMatch(/bold/); +         expect(element('.doc-example-live p:first').prop('className')).not().toMatch(/red/); + +         input('bold').check(); +         expect(element('.doc-example-live p:first').prop('className')).toMatch(/bold/); + +         input('red').check(); +         expect(element('.doc-example-live p:first').prop('className')).toMatch(/red/); +       }); + +       it('should let you toggle string example', function() { +         expect(element('.doc-example-live p:nth-of-type(2)').prop('className')).toBe(''); +         input('style').enter('red'); +         expect(element('.doc-example-live p:nth-of-type(2)').prop('className')).toBe('red'); +       }); + +       it('array example should have 3 classes', function() { +         expect(element('.doc-example-live p:last').prop('className')).toBe(''); +         input('style1').enter('bold'); +         input('style2').enter('strike'); +         input('style3').enter('red'); +         expect(element('.doc-example-live p:last').prop('className')).toBe('bold strike red'); +       }); +     </file> +   </example> + +   ## Animations + +   Example that demostrates how addition and removal of classes can be animated. +     <example animations="true">       <file name="index.html">        <input type="button" value="set" ng-click="myVar='my-class'"> | 
