Im doing Angularjs code and have a strange error:
"Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 2 of the expression [{{asset.sn}}] starting at [{asset.sn}}]. http://errors.angularjs.org/1.3.11/$parse/syntax?p0=%7B&p1=invalid%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
What it means and why it's displyed?
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 code:
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;
}
}
}]);
You're trying to do a 2-way binding (param : "="
) to what's written in param
, but that is not an object or a variable, it's an expression. Either lose the {{}}
or change your scope.param binding to be to a string:
scope: {
param: '@'
},
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With