我正在做Angularjs代码并且有一个奇怪的错误:
“错误:[$ parse:syntax]语法错误:从[{asset.sn}}]开始,表达式[{{asset.sn}}]的第2列处的令牌'{'无效键。 http://errors.angularjs.org/1.3.11/ $解析/语法P0 =%7B&安培; P1 =无效%20key&安培; P2 = 2及P3 =%7B%7Basset.sn%7D%7D&安培; P4 =%7Basset.sn%7D%7D minErr /< @ http://localhost:8000/app/vendor/angular/angular.js:63:12
这意味着什么以及它为什么显示出来?
HTML code:
<table class="table" ng-table="tableParams" show-filter="false" ng-class="{loadingtable : loading}" ng-show="showResults">
<tbody>
<tr ng-repeat="asset in assets">
<td class="col-md-4" data-title="'Serial Number'" header-class="text-left" search-word-marker param="{{asset.sn}}"></td>
<td class="col-md-4" data-title="'Asset Name'" accesskey="" header-class="text-left" search-word-marker param="{{asset.asset_name}}"></td>
<td class="col-md-2" data-title="'Asset Type'" header-class="text-left">{{asset.asset_type}}</td>
<td class="col-md-2" data-title="'Tags'" header-class="text-left">{{asset.tags}}</td>
<td class="col-md-1">
<div class="btn-group">
<span>
<button type="button" class="btn btn-sm btn-primary" ng-click="viewAsset(asset.sn);">{{'VIEW' | translate}}</button>
</span>
</div>
</td>
</tr>
</tbody>
</table>
DIRECTIVE代码:
Application.Directives.directive('searchWordMarker', ['$log', '$rootScope', function ($log, $rootScope) {
return {
restrict: 'A',
scope: {
param: '='
},
//template: "{{myNewString}}",
//replace: false,
link: function (scope, el, attr) {
var myString = attr.param;
var searchWord = $rootScope.searchWord;
var regex = new RegExp(searchWord, "g");
var myNewString = myString.replace(regex, "<B>" + searchWord + "</B>");
el[0].innerHTML = myNewString;
}
}
}]);
答案 0 :(得分:10)
你试图对param : "="
中的内容进行双向绑定(param
),但这不是对象或变量,而是表达式。要么丢失{{}}
,要么将scope.param绑定更改为字符串:
scope: {
param: '@'
},
答案 1 :(得分:1)
<table class="table" ng-table="tableParams" show-filter="false" ng-class="{loadingtable : loading}" ng-show="showResults">
<tbody>
<tr ng-repeat="asset in assets">
<td class="col-md-4" data-title="'Serial Number'" header-class="text-left" search-word-marker param="asset.sn"></td>
<td class="col-md-4" data-title="'Asset Name'" accesskey="" header-class="text-left" search-word-marker param="asset.asset_name"></td>
<td class="col-md-2" data-title="'Asset Type'" header-class="text-left">{{asset.asset_type}}</td>
<td class="col-md-2" data-title="'Tags'" header-class="text-left">{{asset.tags}}</td>
<td class="col-md-1">
<div class="btn-group">
<span>
<button type="button" class="btn btn-sm btn-primary" ng-click="viewAsset(asset.sn);">{{'VIEW' | translate}}</button>
</span>
</div>
</td>
</tr>
</tbody>
</table>