If I register an element-oriented directive with AngularJS ahead of time, can I then simply directly inject into the DOM (e.g. via document.appendChild) a node matching the directive element (e.g. <my-directive-name my-attribute='foo'></my-directive-name>, and AngularJS will render said directive in its place (perhaps needing a manual digest trigger)?
my-directive-template.html
<div>
hello world
</div>
my-directive-name.js
function MyDirectiveName() {
return {
scope: {
'myAttribute': '&',
},
template: template,
replace: true,
controller: controller,
restrict: 'E',
// ...
};
}
Angular configuration:
//...
angular.directive('my-directive-name', require('my-directive-name'))
//...
Start DOM:
<body></body>
Then I dynamically append a child node:
<body>
<my-directive-name my-attribute='foo'>
</my-directive-name>
</body>
Then I do something to make Angular realize that something has changed (what is this?):
End DOM:
<body>
<div>
hello world
</div>
</body>
ng-ifbut I might don't quite get what you intend to do.ng-if,ng-show,ng-repeat, etc. to render content based on data types in plenty of projects. I can't give you a solution to a hypothetical "I don't know what it is ahead of time" type question; why wouldn't you know ahead of time, somewhere in the flow of the app? you aren't letting the users pick the HTML they want rendered on the page, after all....