Rating是一个用于打分或排名的控件。看一个最简单的例子:

 <!DOCTYPE html>
<html ng-app="ui.bootstrap.demo" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="/Content/bootstrap.css" rel="stylesheet" />
<title></title> <script src="/Scripts/angular.js"></script>
<script src="/Scripts/ui-bootstrap-tpls-1.3.2.js"></script>
<script> angular.module('ui.bootstrap.demo', ['ui.bootstrap']).controller('RatingDemoCtrl', function ($scope) {
$scope.rate = 7;
$scope.max = 10;
$scope.isReadonly = false; $scope.hoveringOver = function (value) {
$scope.overStar = value;
$scope.percent = 100 * (value / $scope.max);
};
});
</script> </head>
<body style="padding:10px">
<div ng-controller="RatingDemoCtrl">
<uib-rating ng-model="rate" max="max" read-only="isReadonly" on-hover="hoveringOver(value)" on-leave="overStar = null" titles="['one','two','three']" ></uib-rating>
<span class="label" ng-class="{'label-warning': percent<30, 'label-info': percent>=30 && percent<70, 'label-success': percent>=70}" ng-show="overStar && !isReadonly">{{percent}}%</span>
</div>
</body>
</html>

效果是这样:

uib-rating可以使用的属性有:

属性名 默认值 备注
max 5 图标的最大个数
ng-model   当前图标数量
on-hover(value)   一个可选的表达式(函数),当鼠标放在图标上时触发
on-leave()    
rating-states null 一个数组,定义所有图标的属性。默认的模板中,使用state-on和state-off定义图标的类名
read-only false 是否只读
titles ['one', 'two', 'three', 'four', 'five'] 一个字符串数组,定义所有图标的标题(鼠标悬停在图标上时会显示标题)
enable-reset true 点击当前分数的图标会将分数重置为0
state-off null 一个变量,表示未选中图标的状态
state-on null 一个变量,表示选中了的图标的状态

这些属性中,rating-states、state-on和state-off可以自定义图标的类名

例如,使用rating-states为每个图标分别设置选中和未选中的类名

$scope.ratingStates = [
{ stateOn: 'glyphicon-ok-sign', stateOff: 'glyphicon-ok-circle' },
{ stateOn: 'glyphicon-star', stateOff: 'glyphicon-star-empty' },
{ stateOn: 'glyphicon-heart', stateOff: 'glyphicon-ban-circle' },
{ stateOn: 'glyphicon-heart' },
{ stateOff: 'glyphicon-off' }
];

或者不使用rating-states,而使用state-on和state-off定义所有图标的类:

    <div ng-controller="RatingDemoCtrl">
<uib-rating ng-model="rate" max="max" on-hover="hoveringOver(value)" on-leave="overStar = null" state-on="'glyphicon-ok-sign'" state-off="'glyphicon-ok-circle'" >
</uib-rating>
</div>

用uibRatingConfig可以设置Rating的全局属性。如:

 angular.module('ui.bootstrap.demo', ['ui.bootstrap'])
.config(['uibRatingConfig', function (uibRatingConfig) {
uibRatingConfig.max = 3;
uibRatingConfig.stateOn = 'glyphicon-ok-sign';
uibRatingConfig.stateOff = 'glyphicon-ok-circle';
}])
.controller('RatingDemoCtrl', function ($scope) {
$scope.rate = 2;
});

默认的全局属性是:

{
max: 5,
stateOn: null,
stateOff: null,
enableReset: true,
titles : ['one', 'two', 'three', 'four', 'five']
}

目录:

AngularJs的UI组件ui-Bootstrap分享(一)

AngularJs的UI组件ui-Bootstrap分享(二)——Collapse

AngularJs的UI组件ui-Bootstrap分享(三)——Accordion

AngularJs的UI组件ui-Bootstrap分享(四)——Datepicker Popup

AngularJs的UI组件ui-Bootstrap分享(五)——Pager和Pagination

AngularJs的UI组件ui-Bootstrap分享(六)——Tabs

AngularJs的UI组件ui-Bootstrap分享(七)——Buttons和Dropdown

AngularJs的UI组件ui-Bootstrap分享(八)——Tooltip和Popover

AngularJs的UI组件ui-Bootstrap分享(九)——Alert

AngularJs的UI组件ui-Bootstrap分享(十)——Model

AngularJs的UI组件ui-Bootstrap分享(十一)——Typeahead

AngularJs的UI组件ui-Bootstrap分享(十二)——Rating

AngularJs的UI组件ui-Bootstrap分享(十三)——Progressbar

AngularJs的UI组件ui-Bootstrap分享(十四)——Carousel


最新文章

  1. 计算字符串高度 iOS
  2. Android Studio 引入 Fresco
  3. mysql线上一些隐患查询sql
  4. -----------------------------------项目中整理的非常有用的PHP函数库(一)-----------------------------------------------------
  5. xmind的第四天笔记
  6. json2.js使用参考
  7. canvas使用注意点
  8. CPU Benchmarks
  9. Java实现Http服务器(二)
  10. lesson6:jmeter和badboy配合使用
  11. iconv编码转换指令
  12. 使用SQL Server 2005数据库管理工具 - 初学者系列 - 学习者系列文章
  13. Hibernate3 第四天
  14. dip2px
  15. nodejs模块引用
  16. Java中String、StringBuilder、StringBuffer的区别
  17. GitHub和75亿美金
  18. 如何使用post请求下载文件
  19. cordova热更新插件的使用:cordova-hot-code-push-plugin
  20. jscript DOM操作

热门文章

  1. CSS选择器详解
  2. navicat 快捷键
  3. java, mybatis, 调用mysql存储过程
  4. java 的 linq,不要再写令人讨厌的 for 了!
  5. Python’s SQLAlchemy vs Other ORMs[转发 0]
  6. 我需要在Web上完成一个图片上传的功能后续(+1)
  7. Shell脚本快速入门
  8. UEditor-从客户端(editorValue=&quot;&lt;p&gt;asd&lt;/p&gt;&quot;)中检测到有潜在危险的 Request.Form 值。
  9. Kotlin Groovy Style Builder
  10. 为iOS的mobileconfig文件进行签名