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

[Bug Report] a bug in applyDirectivesToNode function #7180

Closed
coffeecxy opened this issue Apr 21, 2014 · 2 comments
Closed

[Bug Report] a bug in applyDirectivesToNode function #7180

coffeecxy opened this issue Apr 21, 2014 · 2 comments

Comments

@coffeecxy
Copy link

Hi, Angularjs, I think I found something wrong.
I create thress directives name my-d, my-e and my-f just like bellow
http://plnkr.co/edit/zTulGu270PM0qTSlI7Fj?p=preview
here my-d, my-e with scope true, and my-f with scope be an Object, and my-f has a template. In the html, I just put the three directives in a div tag, and nothing wrong. the template of my-f just shown.

But, when I change directive myE's name to myF, and vice versa.
and open Chrome's Developer tools, there's an Error

Error: [$compile:multidir] Multiple directives [myE, myF] asking for new/isolated scope on:

I think this is a bug in applyDirectivesToNode function, what I mentioned bellow is for the file angular.js 1.2.16.

line 6276-6288

if (directiveValue = directive.scope) {
  newScopeDirective = newScopeDirective || directive;

  // skip the check for directives with async templates, we'll check the derived sync
  // directive when the template arrives
  if (!directive.templateUrl) {
    assertNoDuplicate('new/isolated scope', newIsolateScopeDirective, directive,
      $compileNode);
    if (isObject(directiveValue)) {
      newIsolateScopeDirective = directive;
    }
  }
}

if the current directive's scope property is an Object, then newIsolateScopeDirective = directive; so if there's another directive in the directives array after the current directive, then the assertNoDuplicate will always throw an Error, because in assertNoDuplicate function

line 6878-6883

function assertNoDuplicate(what, previousDirective, directive, element) {
  if (previousDirective) {
    throw $compileMinErr('multidir', 'Multiple directives [{0}, {1}] asking for {2} on: {3}',
      previousDirective.name, directive.name, what, startingTag(element));
  }
}     

once previousDirective is not undefined, then an error is thrown. And the sccond code snippet will trigger prolem. But the first one will not, because my-f is the last directive in the directives array.

I can't carry out a solution for this issue. Looking forward to your replay!

@caitp
Copy link
Contributor

caitp commented Apr 21, 2014

I can't carry out a solution for this issue. Looking forward to your replay!

Sure you can, just write a failing test (a case where multiple new or isolate scopes are created in a single directive where the directive doesn't throw) and hack on it until it does ;)

I can try to make that more sane tomorrow if you don't want to do it.

@caitp caitp self-assigned this Apr 21, 2014
@caitp caitp added this to the 1.3.0-beta.6 milestone Apr 21, 2014
@IgorMinar IgorMinar modified the milestones: 1.3.0-beta.7, 1.3.0-beta.6 Apr 22, 2014
@caitp caitp modified the milestones: 1.3.0, 1.3.0-beta.8 May 1, 2014
@caitp
Copy link
Contributor

caitp commented May 12, 2014

I think this is actually a dupe of #4421

@caitp caitp closed this as completed May 12, 2014
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