angularjs 控制style
2015-10-18 22:28
671 查看
ng-if="curtab==tab1" ng-style="{color: #4596CE;}"或
ng-style="{color: myColor}"在angular中为我们提供了3种方案处理class:1:scope变量绑定,如上例。(不推荐使用)2:字符串数组形式。3:对象key/value处理。1、scope变量绑定例子:
function ctr($scope){
$scope.test =“classname”;
}<div class=”{{test}}”></div>
2、字符串数组形式
function Ctr($scope) {其结果是2中组合,isActive表达式为true,则 active,否则inactive。3、对象key/value例子
$scope.isActive = true;
}<div ng-class="{true: 'active', false: 'inactive'}[isActive]">
</div>
<div ng-class {'selected': isSelected, 'car': isCar}"> </div>当 isSelected = true 则增加selected class,当isCar=true,则增加car class,所以你结果可能是4种组合。个人推荐用2,3两种方式angularjs 常用样式相关指令:ng-class -
use when the set of CSS styles is static/known ahead of time
ng-style -
use when you can't define a CSS class because the style values may change dynamically. Think programmable control of the style values.
ng-show and ng-hide -
use if you only need to show or hide something (modifies CSS)
ng-if -
new in version 1.1.5, use instead of the more verbose ng-switch if you only need to check for a single condition (modifies DOM)
ng-switch -
use instead of using several mutually exclusive ng-shows (modifies DOM)
ng-disabled and ng-readonly -
use to restrict form element behavior
ng-animate -
new in version 1.1.4, use to add CSS3 transitions/animations
相关文章推荐
- AngularJS1.3一些技巧
- AngularJS-Controller的使用-读书笔记
- AngularJS 实现按需异步加载实例代码
- 浅析angular
- AngularJS 实现按需异步加载实例代码
- angular controller 依赖声明
- Angularjs 通过asp.net web api认证登录
- 在AngularJS应用中实现认证授权
- angularjs给Model添加拦截过滤器,路由增加限制,实现用户登录状态判断
- AngularJS 应用身份认证的技巧
- 6个强大的AngularJS扩展应用
- AngularJS 实现按需异步加载
- angularjs面试题
- AngularJS报错:[$injector:unpr] Unknown provider: $templateRequestProvider
- AngularJS学习笔记之directive——scope选项与绑定策略
- angular.extend
- angularjs于directive声明scope说明何时以及如何使用对象修饰符
- 学习笔记-AngularJs(十)
- angular ng-href
- [AngularJS]Argument 'xxxx' is not a function, got undefined