angular2-template-loader icon indicating copy to clipboard operation
angular2-template-loader copied to clipboard

More restrictive templateUrl and styleUrls regex

Open ghetolay opened this issue 9 years ago • 2 comments

Hi,

In my code I'm currently dynamically creating component metadata and it's being replaced. A more restrictive regex would avoid that.

/templateUrl\s*:\s*(['"`].*['"`])/g
/styleUrls\s*:(\s*\[.*['"`]+.*\])/g

Theses would be enough for me. Introducing quote allows it to differentiate when we are using programmatic code like referencing to a variable and when we are statically setting an url through a string.

But maybe including '.html' or even checking for a preceding @Component may be even better. Dunno if it's worth the trouble.

ghetolay avatar Oct 20 '16 13:10 ghetolay

I'm facing similar problem when using it with an hybrid ng1/ng4 app. It replaces templateUrl occurrences on ng1 templates, which it is unwanted behavior for this app.

Since it is an angular2-template-loader it would be better if it checked the occurrence within a @Component declaration

daniel-a-melo avatar Apr 20 '17 18:04 daniel-a-melo

Also running into this issue with a hybrid app, where an Angular component needs to pass a templateUrl to an AngularJS component. Our AngularJS code uses it's existing build process to put all the templates in $templateCache keyed by their path, so checking for html wouldn't help, but an @Component check would fix it. My current workaround is to assign the string to a variable and then assign the variable to templateUrl.

MikeMatusz avatar Apr 24 '17 14:04 MikeMatusz