0

I have the following code inside my directive.

scope.value = 5;
alert(scope.value);
var compiled = $compile("<div><h1>{{value}}</h1></div>")(scope);
alert(compiled[0].outerHTML)

The first alert value is 5, however, the second one shows...

<div><h1>{{value}}</h1></div>

How do I get it to recognize the value?

1 Answer 1

1

I think alert stops executing so js did not compiled yet.

See this http://plnkr.co/edit/iaJsO8qPk1Knoh1mXRjy?p=preview

setTimeout(function(){
   alert(compiled[0].outerHTML);
 },100);

I added timeout to alert compile so I can see the needle html.

Do console.log(compiled[0].outerHTML);

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

1 Comment

I had the same problem with the angular UI modal (dialogService.openModal(compiled[0].outerHTML);) which is what I was really trying to solve. This seems a little hacky (is it really pausing for 100 milliseconds?) but worked great! Thanks!

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.