Compile angular directive dynamically

2k views Asked by At

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

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

It will not recognize that it's angular directive. The question is - how to recompile scope/element

1

There are 1 answers

1
chris On BEST ANSWER

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

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

Working plunker.