Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

syntax error on directive with replace = true #6979

Closed
brettatoms opened this issue Apr 3, 2014 · 2 comments
Closed

syntax error on directive with replace = true #6979

brettatoms opened this issue Apr 3, 2014 · 2 comments

Comments

@brettatoms
Copy link

I'm not quite sure how to word this in the summary. What's happening if you define a directive with replace=true and the directive template with say an ng-click="" and then when you use the directive and also use ng-click="" the two values of ng-click get concatenated before being evaluated/parsed. This causes a parse error b/c the two statements are separated by a semicolon;

Here's the broken version without the semicolon on the ngClick callback where the directive is used: http://plnkr.co/edit/9M1fCD1NIy8qGmp9e3zQ?p=preview

Here's the working version where the semicolon is added: http://plnkr.co/edit/l7zLT3bwQdCYx6m5gaWe?p=preview

It seems like the expression from the directive template is always appended to the expression where the directive is used so the semicolon is needed where the directive is used.

@tdakhla
Copy link

tdakhla commented May 12, 2014

Here's a similar issue, but this one isn't really fixable (if keeping the replace: true):
http://jsfiddle.net/ZnSdS/2/

Either 1) the template's ng-show should win out and override the outer ng-show, 2) the outer ng-show should win out since it's defined first, or 3) the outer ng-show and the template's ng-show should be merged into 'f && t' (but that would mean at least one false would cause it to not display - not sure if that's the right approach. And not to mention the compiler would have to know to add the &&).

As a general rule of thumb, I don't use replace: true in directives, including ones that use transclusion, to avoid situations like this. Without replace: true, the outer ng-show always wins out (which actually satisfies both 2 and 3), and I'm ok with that.

@Narretz
Copy link
Contributor

Narretz commented Jun 3, 2016

Basically the same issue as #10323
Note that this will probably never get fixed (but we still keep track of it)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants