Angularjs Multiple directives [gridsection, gridsection] asking for template on: <div gridsection=“”>

三世轮回 提交于 2019-12-23 14:59:28

问题


I'm receiving the error: Multiple directives [gridsection, gridsection] asking for templateon : <div gridsection=""> with this code.

I don't see how i'm using nested directives or what is causing this.

html page

<div gridsection ></div>

directive

angular.module('web').directive('gridsection', function() {
    return {
        restrict: 'A',
        replace: false,

        scope: {
      patient: "=patient"
        },
        templateUrl: 'directive/section.html',
        link: function(scope, element, attrs, fn) {


        }
    };
});

directive/section.html

<div>
  here?
</div>

回答1:


It seems like you are declaring the gridsection multiple times in your angular code.




回答2:


I have seen this before when I have a copy of a directive script file in a folder.

i.e. my file structure was

* myDirective.js
* myDirective - copy.js

So essentially I had two directives with the same name.

Doh!

Note originally posted this as a comment but created as an answer in response to comment from @jayjayjay




回答3:


Make sure you didn't include the script tag twice.

I had this issue but only declared the directive once in the markup, turns out it was because I included the script twice.

Note: I saw this in one of the comments for another answer and posted it as an answer for easier access/to prevent it getting lost.




回答4:


For posterity, I was getting this exception because I was trying to create a directive named pager and that was colliding with Bootstrap's pager.




回答5:


I was getting this error for a reason not specified in other answers. I was using declaration for xyz directive as <xyz xyz="xyz"></xyz>

my definition was:

  angular.module('app')
  .directive('xyz', function () {
    return {
      templateUrl: '..../xyz.html',
      restrict: 'EA',
      scope: {
        xyz: '='
      },
      link: function (scope, element, attrs) {
      }
    };
  });

The problem here is that I allowed directive to be used as element and attribute. so <xyz xyz="xyz"></xyz> contained both the declaration which was causing the issue.

Solution is to either restrict the directive to be used as Element only restrict: 'E' OR change the name of the directive to something like xyzView and use it like <xyz-view xyz="xyz"></xyz-view>.



来源:https://stackoverflow.com/questions/25327802/angularjs-multiple-directives-gridsection-gridsection-asking-for-template-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!