ng-repeat获取错误之间的空间

时间:2016-01-04 05:41:25

标签: javascript arrays angularjs

我有数组中的值,单词之间的空格得到错误我替换了问题将被修复的空间但是在U.I我想在空间中显示它。

<td ng-repeat="measure in subsystem.measures track by $index" ng-show={{measure.measureType}}>
      <h4><b>{{measure.measureType}}</b> </h4>
</td>

价值:EB Bill`

错误:

[$parse:syntax] Syntax Error: Token 'Bill' is an unexpected token at column 5 of the expression [EB Bill] starting at [Bill].

2 个答案:

答案 0 :(得分:2)

问题出现在ng-show上,应该评估为trusy ......然而&#39; EB Bill&#39;没有评价任何东西。如果你删除了ng-show指令,那么它应该有效......见下文......

&#13;
&#13;
var app = angular.module("myApp", []);

app.controller("testcontroller", ["$scope",
  function($scope) {
    //$scope.measure.measureType = "EB Bill";
    $scope.subsystem = {
      measures: [{
        measureType: 'one'
      }, {
        measureType: 'two and three'
      }, {
        measureType: 'EB Bill'
      }]
    };
  }
]);
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>

<div ng-app="myApp" ng-controller="testcontroller">
  <div ng-repeat="measure in subsystem.measures track by $index">
    <h4><b>{{measure.measureType}}</b> </h4>
  </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

  

ng-show必须具有true或false值,尝试仅为measureType属性设置true或false数据,我相信你不会收到此错误。