<script>
var a="what's";
console.log(a);//outputs what's;
</script>
但是当我尝试在ng-init
中分配该值时<div ng-init="a='what's'">
Angular正在抛出错误,因为它与
相同ng-init="a='what's'"
那我该怎么做才能解决这个问题?
(注意:我不能在这里ng-init='a="what's"'
因为值来自数据库,可能包含'
和"
符号。)
答案 0 :(得分:2)
<div ng-init="a='what\'s'">{{a}}</div>
var app = angular.module('app',[]);
app.controller('fCtrl', function($scope){
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app">
<div ng-controller="fCtrl">
<div ng-init="a='what\'s'">{{a}}</div>
</div>
</div>