0

I need some help to pass rating value to the HTML page.

Profile.page.ts

logRatingChange(rating){
      //code to calculate avg rating

      rating = 4.5;
  }

Profile.page.html

<ionic4-star-rating #rating
                activeIcon = "ios-star"
                defaultIcon = "ios-star-outline"
                activeColor = "#488aff" 
                defaultColor = "#f4f4f4"
                halfStar = "true"
                readonly="false"
                rating= ""   <-----Passing the rating value here
                fontSize = "32px"
                (ratingChanged)="logRatingChange($event)">
</ionic4-star-rating>

I'm not sure how to pass the rating to the component in HTML page. So sorry if this question is too noobish, since I can't find anything online related to this.

Thank you very much for your help.

2 Answers 2

1

You are looking for Angular data binding: https://angular.io/guide/binding-syntax

The syntax is to either wrap the html attribute in square brackets [propertyName]:

<ionic4-star-rating #rating
                activeIcon = "ios-star"
                defaultIcon = "ios-star-outline"
                activeColor = "#488aff" 
                defaultColor = "#f4f4f4"
                halfStar = "true"
                readonly="false"
                [rating]= "rating"
                fontSize = "32px"
                (ratingChanged)="logRatingChange($event)">
</ionic4-star-rating>

OR you can use the template variable reference syntax: {{varName}}

<ionic4-star-rating #rating
                activeIcon = "ios-star"
                defaultIcon = "ios-star-outline"
                activeColor = "#488aff" 
                defaultColor = "#f4f4f4"
                halfStar = "true"
                readonly="false"
                rating= "{{rating}}"
                fontSize = "32px"
                (ratingChanged)="logRatingChange($event)">
</ionic4-star-rating>
Sign up to request clarification or add additional context in comments.

Comments

0

If you have rating variable as Profile page class, you can use as

<ionic4-star-rating #rating
                activeIcon = "ios-star"
                defaultIcon = "ios-star-outline"
                activeColor = "#488aff" 
                defaultColor = "#f4f4f4"
                halfStar = "true"
                readonly="false"
                [rating]= "rating"
                fontSize = "32px"
                (ratingChanged)="logRatingChange($event)">
</ionic4-star-rating>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.