当我添加评级值时,它仍然是1,这是我的代码:
<div class="star-rating col-sm-4 col-md-4">
<div class="star-rating__wrap">
<input #rating class="star-rating__input" id="star-rating-5" type="radio" name="rating5" value="">
<label class="star-rating__ico fa fa-star-o fa-lg" for="star-rating-5" title="5 out of 5 stars"></label>
<input #rating class="star-rating__input" id="star-rating-4" type="radio" name="rating4" value="4">
<label class="star-rating__ico fa fa-star-o fa-lg" for="star-rating-4" title="4 out of 5 stars"></label>
<input #rating class="star-rating__input" id="star-rating-3" type="radio" name="rating3" value="3">
<label class="star-rating__ico fa fa-star-o fa-lg" for="star-rating-3" title="3 out of 5 stars"></label>
<input #rating class="star-rating__input" id="star-rating-2" type="radio" name="rating2" value="2">
<label class="star-rating__ico fa fa-star-o fa-lg" for="star-rating-2" title="2 out of 5 stars"></label>
<input #rating class="star-rating__input" id="star-rating-1" type="radio" name="rating" value="1">
<label class="star-rating__ico fa fa-star-o fa-lg" for="star-rating-1" title="1 out of 5 stars"></label>
</div>
</div>
<button (click)="addHost(nameHote.value,type.value,rating.value,contact.value,phone.value,email.value,adresse.value)" type="button" class="btn btn-add">
Ajouter
</button>
答案 0 :(得分:0)
请忽略那些对你的问题进行投票的人(今天也有人这样做)。因此我赞成它使其为零。这是一个完全可以接受的问题。请尝试以下方法:
<div class="star-rating col-sm-4 col-md-4">
<div class="star-rating__wrap">
<input [(ngModel)]="ratingNumber" #rating class="star-rating__input" id="star-rating-5" type="radio" name="rating5" [value]="">
<label class="star-rating__ico fa fa-star-o fa-lg" for="star-rating-5" title="5 out of 5 stars"></label>
<input [(ngModel)]="ratingNumber" #rating class="star-rating__input" id="star-rating-4" type="radio" name="rating4" [value]="4">
<label class="star-rating__ico fa fa-star-o fa-lg" for="star-rating-4" title="4 out of 5 stars"></label>
<input [(ngModel)]="ratingNumber" #rating class="star-rating__input" id="star-rating-3" type="radio" name="rating3" [value]="3">
<label class="star-rating__ico fa fa-star-o fa-lg" for="star-rating-3" title="3 out of 5 stars"></label>
<input [(ngModel)]="ratingNumber" #rating class="star-rating__input" id="star-rating-2" type="radio" name="rating2" [value]="2">
<label class="star-rating__ico fa fa-star-o fa-lg" for="star-rating-2" title="2 out of 5 stars"></label>
<input [(ngModel)]="ratingNumber" #rating class="star-rating__input" id="star-rating-1" type="radio" name="rating" [value]="1">
<label class="star-rating__ico fa fa-star-o fa-lg" for="star-rating-1" title="1 out of 5 stars"></label>
</div>
</div>
<button (click)="addHost(nameHote.value,type.value,ratingNumber,contact.value,phone.value,email.value,adresse.value)" type="button" class="btn btn-add">
Ajouter
</button>
您试图通过变量获取值,但所有的radiobox都具有相同的变量名称。因此,您必须使用ngModel来执行此操作。我个人本可以将其作为一个反应形式,但每个都是他们自己的:))
您还需要声明新的&quot; ratingNumber&#39;打字稿中的变量:
ratingNumber: string;