【发布时间】:2016-11-18 04:51:04
【问题描述】:
我正在尝试将Rateyo plugin 与 AngularJS 集成,并在指令中定义的评级值中遇到问题,以下是代码:
编辑:这是工作的plunker
控制器
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://mynahcare.info/frontendapi/hospital_list")
.then(function (response) {$scope.names = response.data.HospitalList;});
});
指令
app.directive("rateYo", function() {
return {
restrict: "A",
scope: {
rating: "="
},
template: "<div id='rateYo'></div>",
link: function( scope, ele, attrs ) {
$(ele).rateYo({
rating: String("{{scope.rating}}"),
starWidth: "20px",
ratedFill: "#ffce59",
readOnly: true
});
}
};
});
这是 HTML 代码
<li ng-repeat="y in names | limitTo: 6"> <a href="<?php echo $this->config->item('search_url');?>{{y.hosurl}}">
<div class="hospital-card">
<div class="hospital-card-img-holder">
<div class="hospital-card-img" style="background-image:url({{y.profile_image}});"></div>
</div>
<h3 class="vlcc-name" title="{{y.clinic_title}}">{{y.clinic_name}}</h3>
<!--Rating begin-->
<div class="doc-rete">
<div rate-yo class="mc-doc-rating"></div>
</div>
<!--Rating ends-->
<p class="hospital-specialist">{{y.rating }} {{y.localty }} {{y.city }}</p>
<p class="vlcc-experince">{{y.clinic_type }}</p>
<p class="vlcc-address">{{y.hos_time }} </p>
</div>
</a>
</li>
控制台中的错误是 Invalid Rating,预期值在 0 到 5 之间
但是如果你看到 API,数据是数字的,有人可以看看我在这里做错了什么吗?
【问题讨论】:
-
你能把它当作一个工作的plunker吗??你也想要完全一样的替代品!
-
@Arvind 我将很快分享 plunker/Jsfiddle 网址,我希望 Rateyo 能正常工作,但不介意它是否也可以替代
-
@Aravind 这里是工作插件:embed.plnkr.co/K8mItqe42jNvDPs3GjyV
-
尝试使用 .success 而不是 .then。
-
@Aravind 尝试了您的代码但无法正常工作,即使在 plunker 中,它也应该彩色星星,现在它的灰色开始
标签: javascript jquery angularjs angularjs-directive