0

I have an AngularJS template, which looks like this:

<script type="text/ng-template" id="my_template">
    {{ name }}
    {{ age }}
</script>

and an object that looks like this:

{
    name: "Bob",
    age: 31
}

Is there a way I can make Angular return HTML after compiling the template and the data object? Please note that the data object in not inside my scope, it's generated randomly and doesn't exist (nor will exist) in the scope in any moment.

I just want to generate an HTML from the template and the data.

Also, note that I'm not willing to $watch the data object for any changes.

1 Answer 1

1

Angular's $interpolate was what I was looking for. The documentation is here: http://docs.angularjs.org/api/ng/service/$interpolate

Basically, what I did is:

var html = $interpolate("my raw template")({ data object});
Sign up to request clarification or add additional context in comments.

Comments

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.