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

please see demo below

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>


Comments

Post a Comment

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -