I've been trying to use the progressbar animation of the powerful bootstrap library I'm used to, which worked great with Angular 1, but sadly not working with Angular 2.
My Angular 2 HTML:
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar"
aria-valuenow="{{enemy.HP}}" aria-valuemin="0" aria-valuemax="{{enemy.HP}}" style="width:{{(enemy.HP/100)*100}}%">
{{enemy.HP}} HP
</div>
</div>
Caused this error:
EXCEPTION: Template parse errors:
Can't bind to 'aria-valuenow' since it isn't a known native property ("iv class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar"
[ERROR ->]aria-valuenow="{{enemy.HP}}" aria-valuemin="0" aria-valuemax="{{enemy.HP}}" style="width:{{(enemy.HP/"): AppComponent@22:2
Can't bind to 'aria-valuemax' since it isn't a known native property ("r progress-bar-striped active" role="progressbar"
aria-valuenow="{{enemy.HP}}" aria-valuemin="0" [ERROR ->]aria-valuemax="{{enemy.HP}}" style="width:{{(enemy.HP/100)*100}}%">
{{enemy.HP}} HP
</div>
"): AppComponent@22:49
If anyone can share an alternative way to use the bootstrap progressbar, I will appreciate it. Thanks!
The binding for attributes like aria-valuenow
should look like [attr.aria-valuenow]
(see more details in Angular 2 docs: Attribute, class, and style bindings). Double curly braces will go away as well.
The width
in the style
attribute should look like [style.width]
(details Angular 2 docs: NgStyle)
So your snippet will look like this:
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar"
[attr.aria-valuenow]="enemy.HP" aria-valuemin="0" [attr.aria-valuemax]="enemy.HP" [style.width]="(enemy.HP/100)*100 + '%'">
{{enemy.HP}} HP
</div>
</div>
You could use ng2-bootstrap and its progress bar component. See the corresponding documentation:
Here is a sample from the documentation:
<div class="row">
<div class="col-sm-4">
<progressbar value="55"></progressbar>
</div>
<div class="col-sm-4">
<progressbar class="progress-striped" value="22"
type="warning">22%</progressbar>
</div>
<div class="col-sm-4">
<progressbar class="progress-striped active"
max="200" value="166" type="danger"><i>166 / 200</i>
</progressbar>
</div>
</div>
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