gihan gihan - 2 months ago 20
Javascript Question

ng-if doesn't work if condition text contains space in AngularJs

I was trying to set values into Angular js Ui grid based on the row.entity values.To do that i have created cellTemplate that check the row values and based on values i did some text styling.

Code Snippet

var statusTemplate='<div>
<span class="txt-color-yellow" ng-if=row.entity.status.name=="Draft">{{row.entity.status.name}}</span>
<span class="txt-color-orange" ng-if=row.entity.status.name==[
"AwaitingReview"]>{{row.entity.status.name}} </span><span
class="txt-color-green" ng-if=row.entity.status.name=="Reviewed">{{row.entity.status.name}}
</span><span class="txt-color-blue" ng-if=row.entity.status.name==[ "Ready ForScripting"]>{{row.entity.status.name}}</span><span
class="txt-color-brown" ng-if=row.entity.status.name==[ "Awating
ScriptReview"]>{{row.entity.status.name}}</span><span
class="txt-color-green" ng-if=row.entity.status.name==[ "ScriptReviewed"]>{{row.entity.status.name}}</span><span
class="txt-color-green" ng-if=row.entity.status.name=="Closed">{{row.entity.status.name}}</span>


';

But the problem was in
ng-if
when trying to check text values with spaces it throws an exception saying
Unterminated quote at columns 25-34 ["Awaiting] in expression [row.entity.status.name==["Awaiting]. etc...
.

Please let me know how can i check the text with spaces in ng-if.

Answer

Change it in all div where write like string pass in the single '' and condition write in double quote ""

ng-if="row.entity.status.name=='Draft'"