Compile angular directive dynamically

If I add angular material directive md-button like this:

angular.element( document.body ).append( '<md-button> Material' )

      

It doesn't acknowledge that this is an angular directive. The question is how to recompile a region / element

+3


source to share


1 answer


Not sure if you should be doing this, but the correct way is to use a function $compile

:

angular.element(document.body).append($compile('<md-button> Material')($scope))

      



The plunker works .

+6


source







All Articles