Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
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

Description

@coffeecxy

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!

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions