1

I have a CSS property value pair something like this:

style="width:60%"

This works fine. But when I try to concat something like this inside of ng-repeat:

               <tbody ng-show="!vm.loading">
                    <tr ng-repeat="item in vm.currentBatches.items | orderBy: vm.sortBy.current_batch">


                        <td class="table-text" ng-show="!item.showRefreshForApiLoading">


                                <div class="progress progress-medium" ng-show="item.batch_status==='in progress'">
                                    <div class="progress-inner">
                                        <div class="segment" style="'width: "+item.succeeded_time_pct+"%">
                                        <div class="bar status-ok bar-striped"></div>
                                        </div>
                                    </div>
                                </div>
                                <span class="progress-label status-ok" ng-show="item.batch_status==='in progress' && item.progressFlag !== 'NA'">In Progress</span>

Why does this not work ?

style="width: "+item.succeeded_time_pct+"%">

This says CSS property value expected,

What am I doing wrong?

1

2 Answers 2

4

You can fix it using:

<div class="segment" ng-style="{'width': item.succeeded_time_pct + '%' }">

ng-style is a directive which angular offers to apply style properties dynamically

Ref: https://docs.angularjs.org/api/ng/directive/ngClass

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

3 Comments

It fails. Unexpected end of expression: {'width': item.succeeded_time_pct+
ng-style="{'width': item.succeeded_time_pct+'%'}" can you check the quotes if they match the answer?
update the answer @StrugglingCoder, plz check "%" should have been '%'
0

You can try also:

<div class="segment" style="width: {{item.succeeded_time_pct}}%">

But I recommend the usage of ng-class or ng-style, like the other fellows sayed.

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.