Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compare string with ng-if angularjs

Tags:

angularjs

When i try to compare the string with ng-if from angularjs, i m getting the errors in console.

Below are my data:

value for {{reports[0]}} is:

{"name":null,"discount":0,"margin":0,"reportType":"REPORT_TOP_SELLERS","revenue":0,"variantKey":null,"rank":1,"productKey":"10692-1_en_US","purchasedUnits":0,"abandonedUnits":0}

value for {{reports[0].reportType}} is:

REPORT_TOP_SELLERS

Below are the code which throws the Error:

<div ng-if="{{reports[0].reportType}} === 'REPORT_TOP_SELLERS'">

Error:
Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 2 of the expression [{{reports[0].reportType}} === 'REPORT_TOP_SELLERS'] starting at [{reports[0].reportType}} === 'REPORT_TOP_SELLERS'].

Please help.

like image 742
user2057006 Avatar asked Sep 08 '17 05:09

user2057006


3 Answers

change html code :

<div ng-if="reports[0].reportType == 'REPORT_TOP_SELLERS'">
like image 100
Chandru Avatar answered Oct 26 '22 22:10

Chandru


Use without the expression, it should be,

if its angular

<div *ngIf="reports[0].reportType === 'REPORT_TOP_SELLERS'">

angularjs

<div ng-if="reports[0].reportType === 'REPORT_TOP_SELLERS'">
like image 43
Sajeetharan Avatar answered Oct 27 '22 00:10

Sajeetharan


do not use brackets just use it direct

<div ng-if="reports[0].reportType === 'REPORT_TOP_SELLERS'">
like image 23
jitendra varshney Avatar answered Oct 27 '22 00:10

jitendra varshney