0

I have an HTML template that I need to insert on specific views, so I was wondering if this possible in AngularJS and if yes how? Any example is highly appreciated. Thanks

Note: I've checked ng-html but as far as I understood it binds HTML to a scope variable which I can access from view, but that is not applicable for me as the html template I am trying to inject is big and I would rather have it in a separate html file, example: divsToInsert.html

1 Answer 1

1

I'm assuming you're doing this from a controller; if so, you can use jQuery to insert ng-include into your view in the right spot.

It's been a while since I had to do this, so I don't exactly remember, but I believe you will also have to wrap the ng-include in a call to $compile

EDIT: I found a code snippet from an old project that reminded me how to do this. You basically want to do the following:

$('some-html-identifier').append($compile("<ng-include src=\"'path/to/template.html'\"></ng-include>"));

The only think you have to do differently is inject $compile as a dependency to your controller.

Sign up to request clarification or add additional context in comments.

1 Comment

You shouldn't be doing DOM manipulation inside the Controller, it's not a good practice.

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.