9

I want to style my progress bar using with percentages but following ng documentation I can't seem to grasp it. It should be 20% with, but it's 100% (default).

Fiddle: http://jsfiddle.net/u6xp8csh/

Here is what I have tried

HTML

<div data-ng-app>
    <div data-ng-controller="ProgressBarController">
        <div class="progress-bar-container">
            <div class="progress-bar" ng-style="{'width' : '{{ progress }}'% }">{{ progress }}</div>
        </div>
    </div>
</div>

JS

function ProgressBarController($scope) {
    $scope.progress = 20;
}

CSS

.progress-bar-container {
    width: 300px;
    height: 100px;
    box-sizing: border-box;
    border: 1px solid black;
}
.progress-bar {
    height: 100px;
    background-color: green;
}

4 Answers 4

11

progress field accessible without '{{':

 ng-style="{'width' : progress + '%' }"

http://jsfiddle.net/gc343w7x/

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

Comments

5

The inside of the ng-style is stripped down Javascript, so you have a string '{{progress}}' immediately followed by the modulus operator %.

ng-style="{width: progress + '%'}"

will suffice.

Comments

2

Move the % inside of the quotes.

ng-style="{'width' : '{{ progress }}%' }">

Comments

2
 <p class="bar" [style.width.%]="value">
        <span>Helo The World</span>
    </p>

For More Detailes click here

1 Comment

While this code may provide a solution to OP's problem, it is highly recommended that you provide additional context regarding why and/or how this code answers the question. Code only answers typically become useless in the long-run because future viewers experiencing similar problems cannot understand the reasoning behind the solution.

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.