Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 66007a4

Browse files
xjamundxIgorMinar
authored andcommitted
docs(ngClass): updated the example with string, map and array syntax
Closes #3084
1 parent 7f14cde commit 66007a4

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

src/ng/directive/ngClass.js

+60-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,66 @@ function classDirective(name, selector) {
9393
* names of the properties whose values are truthy will be added as css classes to the
9494
* element.
9595
*
96-
* @example
96+
* @example Example that demostrates basic bindings via ngClass directive.
97+
<example>
98+
<file name="index.html">
99+
<p ng-class="{strike: strike, bold: bold, red: red}">Map Syntax Example</p>
100+
<input type="checkbox" ng-model="bold"> bold
101+
<input type="checkbox" ng-model="strike"> strike
102+
<input type="checkbox" ng-model="red"> red
103+
<hr>
104+
<p ng-class="style">Using String Syntax</p>
105+
<input type="text" ng-model="style" placeholder="Type: bold strike red">
106+
<hr>
107+
<p ng-class="[style1, style2, style3]">Using Array Syntax</p>
108+
<input ng-model="style1" placeholder="Type: bold"><br>
109+
<input ng-model="style2" placeholder="Type: strike"><br>
110+
<input ng-model="style3" placeholder="Type: red"><br>
111+
</file>
112+
<file name="style.css">
113+
.strike {
114+
text-decoration: line-through;
115+
}
116+
.bold {
117+
font-weight: bold;
118+
}
119+
.red {
120+
color: red;
121+
}
122+
</file>
123+
<file name="scenario.js">
124+
it('should let you toggle the class', function() {
125+
126+
expect(element('.doc-example-live p:first').prop('className')).not().toMatch(/bold/);
127+
expect(element('.doc-example-live p:first').prop('className')).not().toMatch(/red/);
128+
129+
input('bold').check();
130+
expect(element('.doc-example-live p:first').prop('className')).toMatch(/bold/);
131+
132+
input('red').check();
133+
expect(element('.doc-example-live p:first').prop('className')).toMatch(/red/);
134+
});
135+
136+
it('should let you toggle string example', function() {
137+
expect(element('.doc-example-live p:nth-of-type(2)').prop('className')).toBe('');
138+
input('style').enter('red');
139+
expect(element('.doc-example-live p:nth-of-type(2)').prop('className')).toBe('red');
140+
});
141+
142+
it('array example should have 3 classes', function() {
143+
expect(element('.doc-example-live p:last').prop('className')).toBe('');
144+
input('style1').enter('bold');
145+
input('style2').enter('strike');
146+
input('style3').enter('red');
147+
expect(element('.doc-example-live p:last').prop('className')).toBe('bold strike red');
148+
});
149+
</file>
150+
</example>
151+
152+
## Animations
153+
154+
Example that demostrates how addition and removal of classes can be animated.
155+
97156
<example animations="true">
98157
<file name="index.html">
99158
<input type="button" value="set" ng-click="myVar='my-class'">

0 commit comments

Comments
 (0)