-
Notifications
You must be signed in to change notification settings - Fork 27.4k
feat($interpolate): Add 'strictMode' option on $interpolateProvider to tell $compileProvider not to denormalize directives template. #6453
Conversation
… to tell $compileProvider not to denormalize directives template. With this option set to true, the default symbols '{{' and '}}' are left as is in the templates, and only the startSymbol and endSymbol defined by the developer are used.
I'm sorry, but I wasn't able to verify your Contributor License Agreement (CLA) signature. CLA signature is required for any code contributions to AngularJS. Please sign our CLA and ensure that the CLA signature email address and the email address in this PR's commits match. If you signed the CLA as a corporation, please let us know the company's name. Thanks a bunch! PS: If you signed the CLA in the past then most likely the email addresses don't match. Please sign the CLA again or update the email address in the commit of this PR. |
Hi @fredericbonjour thanks for the PR, but it's not clear from it why do you need this feature. You are also missing tests and CLA. I'm going to close this because I'm having a really hard time thinking a valid situation when you would want it. All reusable components must always be created with the default interpolation symbols, otherwise they won't be reusable. if you don't need reusability then you can use your custom symbols that you use throughout your app. |
I've signed as a corporation. I've filled, scanned and emailed the form yesterday. |
Thanks, @IgorMinar! First of all, I'm using Twig for server-side templating. To avoid any problem, I've changed the My server generates a template for a Directive, which looks like this:
These pieces of data are embedded so that the Directive does not need to fetch them from the server, for performance reasons. But, when parsing the Directive template, Angular denormalizes it and I end up with that:
The end of the object declaration in the JSON value of my Here is a couple of questions:
Thank you for your answers, and for the really great work done in AngularJS! |
+1 for handling @fredericbonjour You can always json_pretty_print for a quick fix, as there would be whitespace between the |
I don't think leaving this up to directive authors is the write solution, but we can probably make the denormalize algorithm a bit smarter (if, perhaps, at the expense of performance :() |
We could make $interpolate smarter AngularDart allows you to overwrite the start/endSymbol when invoking |
@fredericbonjour aha, now I see what you are trying to do. This IMO is a bug that should be fixed. We can't denormalize the template carelessly like this. Template denormalization is a rare event, so performance doesn't play a huge role here. correctness is more important. We could tweak the regexp (using non-greedy matcher?) to fix this without making things too complicated. No? Anyone wants to attempt a PR? |
Thank you for your answers, guys! :) I'll try to change the parsing in the
In terms of performance, I think this can be quite efficient: only one single loop over the template string is required. (Can this be more efficient than the actual double regexp Does this look OK for you? |
I suppose that's better than what we have today, but you'll still do the wrong thing for:
or even:
I wonder if three regexp replacements with expressions like:
wouldn't be better (the expressions likely need some tweaking but you get the idea). |
I got the idea :)
|
I think that parsing the template directive for denormalization just like the way it is parsed in |
…rd interpolation symbols In order to support third party modules that do not use the same interpolation symbols as the main app, we implemented denormalization (see dfe9983). This required that 3rd party modules always used the standad `{{` and `}}` interpolation symbols, so that we could correctly denormalise them to the current app's symbols. The problem with this became apparent when an app template using new symbols inadvertently contained one of the standard interpolation symbols. E.g. `<div data-context='{"context":{"id":3,"type":"page"}}">` The double closing curly braces were being incorrectly denormalised. This commit fixes this by allowing the compiler to be configured to know what symbols are being used in templates from a given module. Now modules can specify that what interpolation symbols they use and the compiler will denormalize appropriately. Closes angular#6493 Closes angular#6453
…rd interpolation symbols In order to support third party modules that do not use the same interpolation symbols as the main app, we implemented denormalization (see dfe9983). This required that 3rd party modules always used the standad `{{` and `}}` interpolation symbols, so that we could correctly denormalise them to the current app's symbols. The problem with this became apparent when an app template using new symbols inadvertently contained one of the standard interpolation symbols. E.g. `<div data-context='{"context":{"id":3,"type":"page"}}">` The double closing curly braces were being incorrectly denormalised. This commit fixes this by allowing the compiler to be configured to know what symbols are being used in templates from a given module. Now modules can specify that what interpolation symbols they use and the compiler will denormalize appropriately. Closes angular#6493 Closes angular#6453
With this option set to true, the default symbols '{{' and '}}' are left as is in the templates, and only the startSymbol and endSymbol defined by the developer are used.