Angular prepend `TypeError: Cannot read the property" childNodes "from undefined`

foreword

for training, I wanted to create a tab directive that can be used with simple markup (based on user elements, without ng-click or such automatically created tabs).


problem

basic setup was more or less easy, and works well, with one exception: when I want to add is automatically created with the help of tabs .prepend(...), I get the following error, dropped : TypeError: Cannot read property 'childNodes' of undefined.

wired bit: nav is generated and added as expected.

even more wired: use .append(..)works just fine - no errors.


so that's what i did

  • .run - ( - , )
  • ,

, , prepend-

( , )

// create and prepend the navigation
var $template = angular.element($templateCache.get('tabs/templates/tabNav.html'));
var $nav = $compile($template)($scope);

// throws error on local setup
// TypeError: Cannot read property 'childNodes' of undefined
$element.prepend($nav);

. http://plnkr.co/edit/yyTCoPQd4ld3w7kDDFCS?p=preview.

, plunkr ( shebang ), - ​​ .


  • yo angular
  • angular 1.3.15

, , - , .

.

+4

Source: https://habr.com/ru/post/1588893/


All Articles