56 lines
3.2 KiB
HTML
Executable file
56 lines
3.2 KiB
HTML
Executable file
<a href="http://github.com/angular/angular.js/tree/v1.2.0rc1/src/ng/directive/ngStyle.js#L3" class="view-source btn btn-action"><i class="icon-zoom-in"> </i> View source</a><a href="http://github.com/angular/angular.js/edit/master/src/ng/directive/ngStyle.js" class="improve-docs btn btn-primary"><i class="icon-edit"> </i> Improve this doc</a><h1><code ng:non-bindable="">ngStyle</code>
|
|
<div><span class="hint">directive in module <code ng:non-bindable="">ng</code>
|
|
</span>
|
|
</div>
|
|
</h1>
|
|
<div><h2 id="Description">Description</h2>
|
|
<div class="description"><div class="ng-directive-page ng-directive-ngstyle-page"><p>The <code>ngStyle</code> directive allows you to set CSS style on an HTML element conditionally.</p>
|
|
</div></div>
|
|
<h2 id="Usage">Usage</h2>
|
|
<div class="usage">as attribute<pre class="prettyprint linenums"><ANY ng-style="{expression}">
|
|
...
|
|
</ANY></pre>
|
|
as class<pre class="prettyprint linenums"><ANY class="ng-style: {expression};">
|
|
...
|
|
</ANY></pre>
|
|
<h4 id="parameters">Parameters</h4><table class="variables-matrix table table-bordered table-striped"><thead><tr><th>Param</th><th>Type</th><th>Details</th></tr></thead><tbody><tr><td>ngStyle</td><td><a href="" class="label type-hint type-hint-expression">expression</a></td><td><div class="ng-directive-page ng-directive-ngstyle-page"><p><a href="guide/expression">Expression</a> which evals to an
|
|
object whose keys are CSS style names and values are corresponding values for those CSS
|
|
keys.</p>
|
|
</div></td></tr></tbody></table></div>
|
|
<h2 id="Example">Example</h2>
|
|
<div class="example"><div class="ng-directive-page ng-directive-ngstyle-page"><h4>Source</h2>
|
|
<div source-edit="" source-edit-deps="angular.js" source-edit-html="index.html-94" source-edit-css="style.css-95" source-edit-js="" source-edit-json="" source-edit-unit="" source-edit-scenario="scenario.js-96"></div>
|
|
<div class="tabbable"><div class="tab-pane" title="index.html">
|
|
<pre class="prettyprint linenums" ng-set-text="index.html-94" ng-html-wrap=" angular.js"></pre>
|
|
<script type="text/ng-template" id="index.html-94">
|
|
<input type="button" value="set" ng-click="myStyle={color:'red'}">
|
|
<input type="button" value="clear" ng-click="myStyle={}">
|
|
<br/>
|
|
<span ng-style="myStyle">Sample Text</span>
|
|
<pre>myStyle={{myStyle}}</pre>
|
|
</script>
|
|
</div>
|
|
<div class="tab-pane" title="style.css">
|
|
<pre class="prettyprint linenums" ng-set-text="style.css-95"></pre>
|
|
<style type="text/css" id="style.css-95">
|
|
span {
|
|
color: black;
|
|
}
|
|
</style>
|
|
</div>
|
|
<div class="tab-pane" title="End to end test">
|
|
<pre class="prettyprint linenums" ng-set-text="scenario.js-96"></pre>
|
|
<script type="text/ng-template" id="scenario.js-96">
|
|
it('should check ng-style', function() {
|
|
expect(element('.doc-example-live span').css('color')).toBe('rgb(0, 0, 0)');
|
|
element('.doc-example-live :button[value=set]').click();
|
|
expect(element('.doc-example-live span').css('color')).toBe('rgb(255, 0, 0)');
|
|
element('.doc-example-live :button[value=clear]').click();
|
|
expect(element('.doc-example-live span').css('color')).toBe('rgb(0, 0, 0)');
|
|
});
|
|
</script>
|
|
</div>
|
|
</div><h2>Demo</h4>
|
|
<div class="well doc-example-live animate-container" ng-embed-app="" ng-set-html="index.html-94" ng-eval-javascript=""></div>
|
|
</div></div>
|
|
</div>
|