Let's say we are passing initial data from php to Angular' view by Mustache, and the data is some string that contain quotes, like "Can't delete item".
Mustache by default translates the single quote to the ' like:
ng-init="message='Can't delete item'"
but that causes some kind of Angular parsing problem:
Lexer Error: Unterminated quote at columns ... ['] in expression [message='Can't delete item']
I can't use Mustache' triple curlies because then it will be like:
ng-init="message='Can't delete item'"
with the same error in output.
Plunk: http://plnkr.co/edit/GCq4gLrD1NxxCvAsjHy9?p=preview
How can we elegantly solve it on Mustache stage?
I created a directive to place your content in, It will assign the body of directive to scope.message variable.
app.directive('myMessageVar',function(){
return{
restrict :'A',
scope:{
message:'=myMessageVar'
},
link: function (scope, iElement, iAttrs) {
scope.message=iElement.text();
iElement.text('');
}
}
})
In HTML
<span my-message-var="message">Can't delete item</span>
Plunkr: http://plnkr.co/edit/QRtXLX1IiGS6VV0Rc78I?p=preview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With