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
<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>
function ProgressBarController($scope) {
$scope.progress = 20;
}
.progress-bar-container {
width: 300px;
height: 100px;
box-sizing: border-box;
border: 1px solid black;
}
.progress-bar {
height: 100px;
background-color: green;
}
You can combine conditional styling with Angular's property and event binding by using NgStyle and NgClass directives using the Angular template syntax.
The NgClass and NgStyle directives are used to apply style to the HTML element conditionally. The NgClass allows you to apply whole class based on condition whereas NgStyle gives you more flexibility to set individual properties.
NgStylelinkAn attribute directive that updates styles for the containing HTML element. Sets one or more style properties, specified as colon-separated key-value pairs. The key is a style name, with an optional . <unit> suffix (such as 'top.
ng-style does not support ! important . So alternate is to use ng-class instead of ng-style , it will solve the problem. If you want to use ng-style specifically then try to write within html itself- please don't try to write within any function.
progress
field accessible without '{{'
:
ng-style="{'width' : progress + '%' }"
http://jsfiddle.net/gc343w7x/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With