Dmitry Kirpichenko
Dmitry Kirpichenko

Reputation: 33

Compile angular directive dynamically

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

Upvotes: 3

Views: 2055

Answers (1)

chris
chris

Reputation: 1817

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.

Upvotes: 6

Related Questions