Last active
December 16, 2015 19:30
-
-
Save pyrobot/5486002 to your computer and use it in GitHub Desktop.
injecting angular elements from strings of html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html ng-app> | |
<head> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.1/angular.min.js"></script> | |
</head> | |
<body> | |
<script> | |
var | |
domString = '<div>{{1+2}}</div>', | |
injector = angular.injector(['ng']), | |
$compile = injector.get('$compile'), | |
$rootScope = injector.get('$rootScope'), | |
$scope = $rootScope.$new(), | |
dom = $compile(domString)($scope), | |
body = angular.element(document.body); | |
$scope.$digest(); | |
body.append(dom); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment