-1

I have ng-if problem. I want something similar to the php syntax in AngularJS. Example:

<?php 
$A = "Data";
if ( $A == "Data" ) {
$B = "ImData"; 
}
else{
$B = "ImNotData";
}
?>

How to make this syntax in AngularJS ng-if directive?

This does not work:

ng-if="A == 'Data' B='ImData'" 
Vega
  • 27,856
  • 27
  • 95
  • 103
Mr S
  • 1
  • 1
  • 1
    Which version did you use, I believe the latest syntax is `*ngIf` – Timothy Lee Aug 28 '19 at 02:06
  • My AngularJS Version : 1.6.4 – Mr S Aug 28 '19 at 02:08
  • Use a ternary operator – Vega Aug 28 '19 at 02:17
  • something like ng-if="A == 'Data' ? B='ImData' : $B = 'ImNotData'" – Vega Aug 28 '19 at 02:19
  • Thats working @Vega. Thank you very much. You are awesome, you are good person. If you want to answer me, i have one more question for this subject. How can i use AND, OR in this code? Example; `ng-if="A == 'Data' ? B='ImData' : $B = 'ImNotData' && C== 'OtherData' ? D='ImOtherData' : D='ImNotOtherData'" ` Thats true? – Mr S Aug 28 '19 at 02:32
  • Here is a good answer: https://stackoverflow.com/a/6260001/5468463 – Vega Aug 28 '19 at 02:34
  • How about this https://stackoverflow.com/q/20305012/5468463? – Vega Aug 28 '19 at 02:42
  • @Vega Thank you so much for taking the time and helping me solve my problem. I hope you live a good life. God help you... Again thanks... – Mr S Aug 28 '19 at 02:48

1 Answers1

0

suppose you have isTrue Boolean variable in controller

In controller:

$scope.isTrue = true;

In View:

<span ng-if="isTrue == "true">TRUE VALUE</span>
<span ng-if="isTrue != "true">OTHER VALUE</span>
Akash Gadhiya
  • 380
  • 1
  • 15