Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 286
Dmitry Kirpichenko Avatar asked Jul 05 '26 18:07

Dmitry Kirpichenko


1 Answers

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.

like image 118
chris Avatar answered Jul 07 '26 14:07

chris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!