V
V
vasIvas2015-08-10 22:41:45
Angular
vasIvas, 2015-08-10 22:41:45

Why does an error occur if you do not wrap the directive when it is expanded?

Why is there an error in this scenario?
template: '',

<div class="container">
  <sub></sub>
</div>
<script>
  function superDirective(){
    return {
      template: '<div>text</div>'
    }
  }

  function subDirective(){
    return {
      template: '<super></super>',
      replace: true
    }
  }
  
  const app = angular.module("app", []);
  
  app.directive('super', ['$injector', superDirective]);
  app.directive('sub', ['$injector', subDirective]);
</script>

But if you wrap an expandable directive, then no?
template: '<div><super></super></div>',

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-08-10
@vasIvas

https://docs.angularjs.org/error/$compile/multidir...
everything is written there. Specifically your case:
- Multiple directives attempting to define a template or templateURL.
when you do replace: true, your template contains only one element, super, and the current element, sub, is replaced by super, and you end up with two directives referring to the same element. In turn, Super has its own template, and a conflict occurs. If there was no template - everything would be fine.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question