1

My input type="range" outputs 1, 2, 3, 4 or 5.

My question is, how can I change the output to the following using AngularJS?

  • 1: Terrible
  • 2: Below average
  • 3: Average
  • 4: Above average
  • 5: Excellent

Here's my code:

<label for=fader>How would you rate this site?</label>
<input type=range min=1 max=5 value=1 id=fader list=ratingsettings ng-model="rating">
<datalist id=ratingsettings>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
</datalist>

<p>{{rating}}</p>

Here's my Plunkr.

1 Answer 1

2

The most direct approach is to use a map object in controller:

$scope.mapRating = {
    1: "Terrible",
    2: "Below average",
    3: "Average",
    4: "Above average",
    5: "Excellent"
};

and then in HTML use it like this:

<p>{{mapRating[rating]}}</p

Demo: http://plnkr.co/edit/MtsjS0fuOSUiWFuA3GeF?p=preview

Sign up to request clarification or add additional context in comments.

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.