首頁  >  文章  >  web前端  >  關於Angularjs渲染 using 指令的星級評分系統的實現

關於Angularjs渲染 using 指令的星級評分系統的實現

小云云
小云云原創
2017-12-23 09:58:501653瀏覽

本文主要介紹了Angularjs渲染的 using 指令的星級評分系統範例,小編覺得挺不錯的,現在分享給大家,也給大家做個參考,希望能幫助到大家更好的掌握Angularjs。

本文介紹Angularjs渲染的 using 指令的星級評分系統範例,分享給大家,具體如下:
我試圖創建靜態使用 angularjs/離子成效甚微的星級評分系統。但目前什麼都不輸出到螢幕上......我是我做錯了嗎?

service.html


 <ion-list>
  <ion-item ng-repeat="business in businessList track by $index" class="item-icon-right">
   <h2>{{business.name}}</h2> {{business.distance}} miles
   <br>
   <p star-rating rating-value="{{business.rating}}" max="rating.max"></p>
   <i class="icon ion-chevron-right icon-accessory"></i>
  </ion-item>
 </ion-list>

directives.js


angular.module(&#39;starter.directives&#39;, [])

.directive(&#39;starRating&#39;, function() {
 return {
  restrict: &#39;A&#39;,
  template: &#39;<ul class="rating">&#39; +
   &#39;<li ng-repeat="star in stars" ng-class="star">&#39; +
   &#39;\u2605&#39; +
   &#39;</li>&#39; +
   &#39;</ul>&#39;,
  scope: {
   ratingValue: &#39;=&#39;,
   max: &#39;=&#39;
  },
  link: function(scope, elem, attrs) {
   scope.stars = [];
   for (var i = 0; i < scope.max; i++) {
    scope.stars.push({
     filled: i < scope.rating
    });
   }
  }
 }
});

services.js


#
.service("BusinessData", [function () {
  var businessData = [
  {
    id: 1,
    serviceId: 1,
    name: &#39;World Center Garage&#39;,
    distance: 0.1,
    rating: 4
  }
];

  return {
    getAllBusinesses: function () {
      return businessData;
    },

    getSelectedBusiness: function(serviceId) {
      var businessList = [];
      serviceId = parseInt(serviceId);
      for(i=0;i<businessData.length;i++) {
        if(businessData[i].serviceId === serviceId) {
          businessList.push(businessData[i]);
        }
      }
      return businessList;
    }
  }
}])

controller.js


.controller(&#39;ServiceCtrl&#39;, function($scope, ServicesData, BusinessData, $stateParams) {
 $scope.service = ServicesData.getSelectedService($stateParams.service);
 $scope.businessList = BusinessData.getSelectedBusiness($stateParams.service);
});

#解決方法1:

controller. js


.controller(&#39;ServiceCtrl&#39;, function($scope, ServicesData, BusinessData, $stateParams) {
 $scope.service = ServicesData.getSelectedService($stateParams.service);
 $scope.businessList = BusinessData.getSelectedBusiness($stateParams.service);
 $scope.ratings = {
   current: 5,
   max: 10
   };

和也修改service.html


#
<p star-rating rating-value="rating.current" max="rating.max"></p>

相關推薦:

##JS完成星級評分功能的實例詳解

基於jQuery的星級評分外掛程式_jquery

用css製作星星級評分_經驗交流

以上是關於Angularjs渲染 using 指令的星級評分系統的實現的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn