Angularjs ui.bootstrap.rating how to post -
i'm trying build star rating system angularjs after bit of research found http://angular-ui.github.io/bootstrap/ since i'm absolutely new angular can't seem figure out how post user selected rating symfony controller.
html:
<div ng-controller="ratingdemoctrl"> <rating ng-model="rate" max="max" readonly="isreadonly" on-hover="hoveringover(value)" on-leave="overstar = null"></rating> <span class="label" ng-class="{'label-warning': percent<30, 'label-info': percent>=30 && percent<70, 'label-success': percent>=70}" ng-show="overstar && !isreadonly">{%verbatim%}{{percent}}%{%endverbatim%}</span> </div><!-- rating controller end-->
angular controller:
tagapp.controller('ratingdemoctrl', function ($scope, $http) { $scope.max = 5; $scope.isreadonly = false; $scope.hoveringover = function(value) { $scope.overstar = value; $scope.percent = 100 * (value / $scope.max); }; $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'} ]; });
you can watch rate
, if user update ration post end using $http
var app = angular.module('app', ['ui.bootstrap']); app.controller('ratingdemoctrl', function($scope, $http) { $scope.max = 5; $scope.isreadonly = false; $scope.hoveringover = function(value) { $scope.overstar = value; $scope.percent = 100 * (value / $scope.max); }; $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' }]; $scope.$watch('rate', function(val) { function sucess(data) { console.log(data); }; function error(response) { console.log(response) alert("can't post " + response.data + " error:" + response.status); } if (val) { var data = { rating: val, user: "userid" // i'm not sure userid } $http.post("yoururl", data).then(sucess, error); } }) });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" /> <script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.0.min.js"></script> <body ng-app="app"> <div ng-controller="ratingdemoctrl"> <rating ng-model="rate" max="max" readonly="isreadonly" on-hover="hoveringover(value)" on-leave="overstar = null"></rating> <span class="label" ng-class="{'label-warning': percent<30, 'label-info': percent>=30 && percent<70, 'label-success': percent>=70}" ng-show="overstar && !isreadonly">{%verbatim%}{{percent}}%{%endverbatim%}</span> </div> </body>
Useful information for students.
ReplyDeleteMEAN Stack Training in Hyderabad
Thank you for sharing any good knowledge and thanks for fantastic efforts. This is good information and really helpful for the people who need information about this. Igained more knowledge from your blog. Keep Doing..
ReplyDeleteoracle training in chennai
oracle training institute in chennai
oracle training in bangalore
oracle training in hyderabad
oracle training
oracle online training
hadoop training in chennai
hadoop training in bangalore