Ask the parsing error caused by a single double quotation mark in ng-init in angularjs.

Source: Internet
Author: User
Ask a question: ng-init initialization. I initialize the title and description of a question. However, single quotation marks and double quotation marks may appear in the title and description, and an error will be reported at the end of the result. Yes & amp; lt ;? Php $ question_title & quot; & #039; aaaa & #039; bbb & #039; & quot ;? & Amp; gt; & amp; lt; divng-ini... ask a question: ng-init initialization. I initialize the title and description of a question. However, single quotation marks and double quotation marks may appear in the title and description, and an error will be reported at the end of the result. Yes


This is the case. Is there any solution? (It seems that some escape character functions in php are invalid)

Reply content:

Ask a question: ng-init initialization. I initialize the title and description of a question. However, single quotation marks and double quotation marks may appear in the title and description, and an error will be reported at the end of the result. Yes


This is the case. Is there any solution? (It seems that some escape character functions in php are invalid)

I am not quite clear about this problem, but I have tried it and can still write it out.
1. using ng-init is not the first time I have seen it, but I don't think it is a good way to define variables. if the page is very long, do you have to look at the html line to find the variable you defined?
2. double quotation marks are allowed in JavaScript. this variable can be easily implemented if you save it in a variable (implemented in controller ).
Example:$scope.text = 'http:/localhost:"3000"/posts.json';
3. the variables defined by angularjs in ng-init do not allow escape characters and single double quotation marks. I did not expect the method for the moment. I will try again.
I don't know much about php. it seems that many people use ng-init.
Http://www.codesec.net/view/167161.html
Escape characters

To print this type of JSON directly in HTML, note that the quotation marks and special characters in HTML are both HEX encoded. the json_encode in PHP can be passed into the second parameter to set the encoding method for special characters:
// JSON_HEX_TAG: ENCODE <and> and other symbols as \ u003C and \ u003E // JSON_HEX_APOS: convert single quotes to \ u0027 // JSON_HEX_QUOT: convert double quotes to \ u0022

//...

Http://blog.csdn.net/wusuopubupt/article...

Http://php.net/htmlspecialchars

You can also useapp.value(key, value)Andapp.constant(key, value)

Http://stackoverflow.com/questions/14523...

Http://hellobug.github.io/blog/angularjs...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.