Angularjs 错误$parse:syntax-token'';是意外的-字符串中的空格

Angularjs 错误$parse:syntax-token'';是意外的-字符串中的空格,angularjs,syntax,Angularjs,Syntax,在我使用两个单词之间有空格的字符串之前,我的代码一直运行良好。 我正在使用AngularJs stringAmi = '<i class="fa fa-user-plus fa-2x" ng-click="demandeAmiNotif(' + $scope.invite + ');"></i>'; 我认为你的模板上有很多嵌套字符串,事情变得越来越复杂。但是,在本例中,缺少函数调用参数的转义,因为它位于字符串中,并且不是作为参数传递的,而是作为字符串传递的 var st

在我使用两个单词之间有空格的字符串之前,我的代码一直运行良好。 我正在使用AngularJs

stringAmi = '<i class="fa fa-user-plus fa-2x" ng-click="demandeAmiNotif(' + $scope.invite + ');"></i>';

我认为你的模板上有很多嵌套字符串,事情变得越来越复杂。但是,在本例中,缺少函数调用参数的转义,因为它位于字符串中,并且不是作为参数传递的,而是作为字符串传递的

var stringAmi = 
    '<i class="fa fa-user-plus fa-2x" ng-click="demandeAmiNotif(' 
    + '\'' + $scope.invite + '\''
    + ');"></i>';
var stringAmi=
'';
但是严肃的说,它看起来很糟糕,我不知道为什么你必须这样做,但是考虑使用不同的方法,一个更容易维护的方式。
angular.module('myApp',[])
.controller('myController',函数($scope){
$scope.invite='Vitor Hugo';
$scope.demandeAmiNotif=函数(名称){
console.log(名称);
};
$scope.stringAmi=
“点击这个!”;
})
.directive('bindHtmlCompile',函数($compile){
返回{
限制:“A”,
链接:函数(范围、元素、属性){
范围$watch(函数(){
返回范围$eval(attrs.bindHtmlCompile);
},函数(值){
html(value&&value.toString());
var compileScope=scope;
if(属性bindHtmlScope){
compileScope=scope.$eval(attrs.bindHtmlScope);
}
$compile(element.contents())(compileScope);
});
}
};
});
元素(函数(){
引导(文档,['myApp']);
});


您仍然必须生成有效的JS。因此执行的代码的结果行是
demandeAmiNotif(Victor Hugo)是的,这是一个语法错误。但它与DemandeAdminotif(Victor)一起工作;我的意思是当$scope.invite=“Victor”;好的,我正在使用Cordova、google maps和angularJs这就是它看起来很糟糕的原因,我现在还有一个错误:错误:[$parse:ueoe]意外的表达式结尾:demandeAmiNotif(@Dionysoson好吧,如果你有机会,试试一个简单的解决方案。关于新的错误,很抱歉,实际上你必须避开撇号而不是引号。我已经更新了我的答案。
var stringAmi = 
    '<i class="fa fa-user-plus fa-2x" ng-click="demandeAmiNotif(' 
    + '\'' + $scope.invite + '\''
    + ');"></i>';