angularJS 样式相关指令
来源:互联网 发布:java学士后6.0 编辑:程序博客网 时间:2024/06/11 04:39
样式相关指令:
- ng-class:写成一个对象的形式,里面内容为class的名字,还需要使用true来激活。
代码示例:
<style type="text/css"> .red {background: red;} .yellow {color: yellow;} </style> <script src="angular.min.js"></script> <script src="http://cdn.bootcss.com/angular.js/1.3.0-beta.13/angular-sanitize.min.js"></script> <script> var m = angular.module('myApp',['ngSanitize']);//引入相应模块 m.controller('Aaa',['$scope',function($scope){ $scope.text = "hello"; }]); </script> <div ng-controller="Aaa"> <div ng-class="{red:true,yellow:true}">{{text}}</div><!--可进行多个class同时绑定,也可动态改变true,false来动态改变class--> </div>
页面结果展示: ![这里写图片描述](http://img.blog.csdn.net/20161106112553165)
- ng-style:设置样式
代码示例:
<div ng-style="{color:'red',background:'yellow'}">{{text}}</div>
页面结果展示:
同时我们可以将style和class等的内容设置为数据,然后将数据进行传递,style方法如下:
代码示例:
<script> var m = angular.module('myApp',['ngSanitize']);//引入相应模块 m.controller('Aaa',['$scope',function($scope){ $scope.text = "hello"; $scope.style ="{color:'red',background:'yellow'}" }]); </script> <div ng-controller="Aaa"> <div ng-style="{{style}}">{{text}}</div><!--注意加上大括号--> </div>
以下均可以提高用户体验,当页面未加载完时,未显示。如同:ng-value、ng-bind
- ng-href
代码示例:
$scope.url = "http://www.baidu.com";<a ng-href="{{url}}">11111</a>
ng-src
ng-attr-(suffix):属性很多,通用的方法
代码示例:
<a ng-attr-href="{{url}}" ng-attr-title="{{title}}" ng-attr-class="{{class}}">11111</a>
0 0
- angularJS 样式相关指令
- angularjs指令 添加CSS样式
- angularJS DOM操作相关指令
- angularjs自定义指令的样式如何设置
- AngularJS初识--指令相关知识总结
- angularJS中input相关指令详解
- AngularJS基础——事件指令及input相关指令
- AngularJS基础——样式指令、DOM操作指令及其它重要指令
- AngularJS 指令
- AngularJS--指令
- angularjs--指令
- angularjs指令
- AngularJS 指令
- 指令<AngularJs>
- AngularJS 指令
- AngularJS 指令
- 指令<AngularJs>
- AngularJS 指令
- Learning Deep Learning
- cypress68013USB固件例程及PCB板
- C++类内存分布
- 对象作用域与Servlet事件监听器
- 深入理解C++的多态性
- angularJS 样式相关指令
- Android获取屏幕的宽度和高度(dp)
- Java任务调度框架Quartz入门教程指南(三)任务调度框架Quartz实例详解深入理解Scheduler,Job,Trigger,JobDetail
- Get,Post请求中文乱码问题有效解决方法
- Android 7.0 新特性--Direct Boot
- 第十一周项目1-(4)哈夫曼编码的算法验证
- Unity Android Callback AndroidJavaProxy
- 微小宝中预估支出是如何计算的?
- JFinal集成Spring