AngularJS逃脱“

AngularJS escape "

我想检查我的状态 "GOOD"(包括双引号)并且我有这个代码:

Inventory Status : <span ng-style="InventoryStatusTextPrint==='\"GOOD\"' ? {'color':'green'} : {'color': 'red'}">{{InventoryStatusTextPrint}}</span>

但是解析器失败了。我收到错误:

angular.min.js:124 Error: [$parse:lexerr] http://errors.angularjs.org/1.6.9/$parse/lexerr?p0=Unterminated%20quote&p1=s%2027-29%20%5B'%5C%5D&p2=InventoryStatusTextPrint%3D%3D%3D'%5C

您可以使用&quot;

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">

Inventory Status : <span ng-style="InventoryStatusTextPrint==='&quot;GOOD&quot;' ? {'color':'green'} : {'color': 'red'}">{{InventoryStatusTextPrint}}</span>

</div>

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.InventoryStatusTextPrint = '"GOOD"';
});
</script>

</body>
</html>