M
M
Maxim Ivanov2016-08-04 13:35:15
Angular
Maxim Ivanov, 2016-08-04 13:35:15

How to dynamically add a directive on Amgular?

When I click in the right place, the page should load

// пытался так
$scope.click = function(typeModel){
     angular.element(document.querySelector(".loadEditor")).html(
       '<editor-content ng-show="visibleEditor.visible"></editor-content>'
     );
}

// пытался так
$scope.click = function(typeModel){
     angular.element(document.querySelector(".loadEditor")).html(
      $compile( '<editor-content ng-show="visibleEditor.visible"></editor-content>')($scope)
     );
}

Angular still does not work out the internal controllers for this directive and does not see anything at all.
Thought to use statically ng-include="editor.html"
But then this template is wedged in when the page is loaded
. In general, it is necessary that when clicking, how is this done correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lega, 2016-08-04
@splincodewd

you can insert ng-if before ng-include, then it will be loaded when necessary

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question