对于角js来说,这是很新的,我有这个错误,因为它是由字符引起的。
Lexer Error: Unexpected next character at columns 8-8 [ö] in expression [item.Teközel].我在控制器开始时就像这样使用ngSanitize
var app = angular.module('xApp', ['smart-table', 'ngSanitize']);但是,在页面呈现过程中,仍然会出现上述错误。
我怎么才能解决这个问题?
发布于 2016-09-09 09:54:45
@Ege作为unicode字符出现在变量名中,此Error: [$parse:lexerr] Lexer Error: Unexpected next character at columns 8-8 [ö] in expression [ctrl.Teközel].错误发生
如果JavaScript对象中有非常少的变量,您可以在视图中执行item['Teközel']来执行数据绑定,但我认为这可能是一种不好的做法,或者不是一种推荐的方法。
如果您有更多的unicode标识符,或者以一种更合适的方式读取这个对非ascii文字#2174的Lexer支持,那么可能会有其他方法来解决这个问题,它可以满足您的需求(以及您正在使用的一组unicode字符),而不是下面使用的2174线程。
要解决这个问题,我们可以修改angular.js文件中的一个函数,该函数指示使用的标识符(即变量名)是否有效。
我在isValidIdentifierStart 1.5.8中修改了这个函数AngularJS,并且数据绑定工作
isValidIdentifierStart: function(ch) {
return ('a' <= ch && ch <= 'z' ||
'A' <= ch && ch <= 'Z' ||
'_' === ch || ch === '$' ||
(129 <= ch.charCodeAt(0) && ch.charCodeAt(0) <= 496));
}可以在用于添加代码的'a' <= ch && ch <= 'z'文件的版本中搜索语句angular.js,以便使函数允许unicode字符。
观景
<!DOCTYPE HTML>
<html ng-app="demo">
<head>
<title>Demo</title>
</head>
<body ng-controller="DefaultController as ctrl">
<span ng-bind="ctrl.Teközel"></span>
<script type="text/javascript" src="scripts/angular.js"></script>
<script type="text/javascript" src="scripts/app/main.js"></script>
</body>
</html>AngularJS码
angular
.module('demo', [])
.controller('DefaultController', DefaultController);
function DefaultController() {
var vm = this;
vm.Teközel = 'Hello, World!';
}要检查标识符名是否有效,我们可以使用此验证器
https://stackoverflow.com/questions/39394145
复制相似问题