0

I have this code:

<div style="cursor:pointer;padding-top:3px;padding-left{{arrow_pos[road.id+'_'+scale.year+'_'+scale.week]}}px"  >
    <div class="arrow_title">{{arrow_title[road.id+'_'+scale.year+'_'+scale.week]}}</div>
    <div class="{{arrow[road.id+'_'+scale.year+'_'+scale.week]}}"></div>
</div>

How do ng-if so that this piece of code generated as Arrow [road.id + '_' + scale.year + '_' + scale.week] is not empty.

I tried this:

<div ng-if="arrow_title[road.id+'_'+scale.year+'_'+scale.week] !=''">
    same code for the two inner divs
</ div>

AngularJS v1.0.7

but it does not work. How to solve my problem.

2 Answers 2

2

ng-if is only available from Angular 1.2 onwards.

Otherwise, the syntax looks correct.

There are a couple of work workaround for Angular 1.0.7:

  1. Using ng-show/ng-hide with the same condition
  2. Using ng-switch:

    <div ng-switch="arrow_title[road.id+'_'+scale.year+'_'+scale.week] !=''">
       <div ng-switch-when="true">
             <!-- your code -->
       </div>
     </div>
    
Sign up to request clarification or add additional context in comments.

Comments

1

The expression:

arrow_title[road.id+'_'+scale.year+'_'+scale.week] !=''

Looks like you are accessing a property dynamically on the arrow_title object.

If this is correct, the result will, most likely, not be '' (unless the property value is a string). The result will either be the property value or undefined.

As @musically_ut describes, ng-if is not available in 1.0.7, but you could use ng-show with this expression:

<div ng-show="arrow_title[road.id+'_'+scale.year+'_'+scale.week]">
same code
</ div>

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.