0

In a scenario where I'm not able to directly control the HTML (it's created by a user), is it proper 'angular etiquette' to iterate through the DOM via javascript and add angular statements/directives before bootstrapping angular manually?

When you can't control the HTML file, is there a way to add angular into the HTML via angular? Or at least in a more angular-friendly way?

1 Answer 1

1

Before the HTML is compiled by angular (the angular compile phase), there is nothing wrong with modifying it. However, once the compile phase has started (i.e. the directive's compile function is being called), you should only modify its children.

To answer your second question - yes, there is a way to bootstrap your HTML via angular without having to add any angular-specific attributes (such as ng-app). This can be done as follows:

angular.element(document).ready(function() {
  angular.bootstrap(document, ['myApp']);
});
Sign up to request clarification or add additional context in comments.

3 Comments

What about adding other ng-attributes before the compile function? Like ng-click or ng-show etc...
The above recommendation applies to directives including ng-attributes.
Sorry, I wasn't clear enough. What about adding other ng-attributes with angular before the compile function? It just feels really hacky to have a block of jquery that runs at the top and then all my angular below. It seems like there should be some way of adding attributes or changing attributes via angular.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.