2

I have object JS was returned by AJAX. In this object there is field map that contents JS code.

When I do: {{data.map.js}} in template HTML, it gives me text instead working JS code.

This is code in template:

{{data.map.js}}
{{data.map.html}}

Object from response Ajax (short code):

   map { html: "<div id="map_canvas" style="width:566px; height:310px;"></div>"
    js: "↵          <script type="text/javascript">↵...}
6
  • Can you show a MWE or part of the code involved ? Have you tried to put the javascript into a <script> tag? Commented May 5, 2015 at 21:37
  • Yes, look question again Commented May 5, 2015 at 21:39
  • You haven't answered my second question :) Also your question excludes any html so we don't know where you are trying to execute the javascript. the angular {{ }} tags are meant to evaluate to text, so this is working as intended. If you wish to execute javascript, I think you should add script tags at the end of your html document. Commented May 5, 2015 at 21:42
  • No, I dont try to put <script> I get JS with tag <script> already Commented May 5, 2015 at 21:53
  • @Hamed you're going to need a directive to handle this, either one that exists or will need to write your own so you can check to verify the external script has completed loading. What specific map or JS code are you trying to integrate? Commented May 5, 2015 at 21:54

2 Answers 2

2

Angular documentation suggests you may be able to execute js code via eval(). I have not done this personally but take a look at https://docs.angularjs.org/guide/expression

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

Comments

2

Use this syntax for angular in html:

{{$on.constructor('alert(1)')()}}

This should work in regular html for ng-app attribute

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.