[英]I am getting error while initialize value containing ' using ng-init in Angularjs
在 Angularjs 中使用 ng-init 初始化包含' 的值時出現錯誤。
例如:
@{
var textToDisplay="Suman's Question";
<div ng-app="" ng-init="myText='@textToDisplay'">
<h1>{{myText}}</h1>
</div>
}
上面的查詢拋出錯誤
[$parse:lexerr]
我正在使用 MVC 來呈現視圖。 預先感謝您的建議..
答案如下
@{
var textToDisplay="Suman's Question";
textToDisplay= textToDisplay.Replace("'", "\\'");
<div ng-app="" ng-init="myText='@textToDisplay'">
<h1>{{myText}}</h1>
</div>
}
如果它使用“,那么代碼就像。
@{
var textToDisplay="Suman"s Question";
textToDisplay= textToDisplay.Replace("\"", """);
<div ng-app="" ng-init="myText='@textToDisplay'">
<h1>{{myText}}</h1>
</div>
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.