Single quote ( ' ) is not supporting in angula

2019-08-19 10:01发布

问题:

How to escape single quote( ' ) in angularjs ng-click

ng-click="editQuesAnsDetails('${fn:escapeXml(quesAnsList.querysearchBO.query)}','${fn:escapeXml(anslist.query_answer)}',

'${anslist.editUrl}','${anslist.filepath}');"

this my angular controller:

App.controller('AskedQuesAnsController',['$scope','$window','AskedQuesAnsServices',function($scope,$window,AskedQuesAnsServices) { 
$scope.quesAnsUpdateCommand={"query":"","answer":"","editUrl":"","deleteUrl":""};
 $scope.editQuesAnsDetails = function(query,answer,editUrl,deleteUrl,filepath){

    $scope.quesAnsUpdateCommand.query=query;

    $scope.quesAnsUpdateCommand.answer=answer;
    $scope.quesAnsUpdateCommand.editUrl=editUrl;
    $scope.quesAnsUpdateCommand.deleteUrl=deleteUrl;
    $scope.quesAnsUpdateCommand.filepath=filepath;
    //alert($scope.moduleUpdateCommand.editModule);
 }

the above code should work for any special symboles

回答1:

You can try using fn:replace() function to escape single quote( ').

<c:set var="singleQuotes">'</c:set>
<c:set var="singleQuotesReplace">\'</c:set>

ng-click="editQuesAnsDetails('${fn:escapeXml(
 fn:replace(quesAnsList.querysearchBO.query,singleQuotes,singleQuotesReplace))}'"

Also JSP javascript escape with JSTL