0

I have custom directive declaration with replace set to true.

When I place it in html with separate close tag:

<div>
    <search-box search="search(query)" query="query" ></search-box>
    <div class="dataDiv">
        <!--other div elements -->
    </div>
</div>

everything works as expected.

But after rewriting html in this way:

<div>
    <search-box search="search(query)" query="query" />
    <div class="dataDiv">
        <!--other div elements -->
    </div>
</div>

directive completely replaces all parent div content with it's template and removes dataDiv from resulting html page.

Is this expected angular behavior or something that can be changed in directive declaration?

Directive:

function SearchBox() {
    return {
        restrict: 'E',
        replace: true,
        template: '...',
        scope: {
            query: '='
        },
        link: function($scope, $element){
            ...
        },
        controller: function ($scope) {
            ...
        }
    }
}
Nick
  • 798
  • 1
  • 7
  • 14

1 Answers1

2

Depending on your doctype you might be giving the wrong meaning to the "closing" slash. by default, yeoman generator and angular-seed use <!doctype html> (html5)

In HTML 5, <foo /> means <foo>. The slash is just syntactic sugar Check this Are (non-void) self-closing tags valid in HTML5?

Depending on the browser implementation, it will add automatically a closing tag in one place or another, just like when you leave bodyor strong open and read the rendered code.

Community
  • 1
  • 1
Eduard Gamonal
  • 8,023
  • 5
  • 41
  • 46