1

I try to create a simple angular app. Its logic looks like:

  1. Enter a city name (for example: haiphong)

  2. Click search -> There will be result showed-> Click on the result -> The map is updated to the new location -> click on the marker -> There will be an info box to show the information.

However, the direction seems to keep the expression as original. Do you have any ideas?

enter image description here

This is what I used to get the info box (inside controller), you can see in detail by plunker link:

$scope.getInfoBoxContent = function (index) { var content = '<div today-info-directive details="' + index +'"></div>'; var compiled = $compile(content)($scope); console.log('compiled', compiled); return compiled[0]; }

http://plnkr.co/edit/pHjqHGNupAZnO5ORSjQW?p=preview

The directive seems to include its template but not parse the expression (for example: {{1+2}})

1 Answer 1

1

use templateUrl, remove all '\' characters copy directive template onto another file and provide it's url to templateUrl of the directive. see if it works. just tested on your fiddle and it did

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

2 Comments

Thanks! It worked!!! However, I have no idea about the difference between putting the content inside the template property and a specific file. It's great if you give me the explanation for this curiosity. By the way, you answer saved my life ^
to tell you the truth, I have no idea why it worked. All I know is that I resent multi-line strings and usually it's a good practice to use separate files for every templates u have. If you want to use multi lines however, use es6 ` backtick notation instead

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.