插入HTML与要运行脚本 [英] Insert HTML with scripts that should run

查看:128
本文介绍了插入HTML与要运行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该应用程序的一个组成部分,从需要被显示为现场HTML服务器获取HTML回来。这是很容易与做NG绑定HTML的不安全=前pression指令(在角1.0.2至少)。

One part of this app gets HTML back from the server that needs to be shown as live HTML. That's easily done with the ng-bind-html-unsafe="expression" directive (in Angular 1.0.2 at least).

但是,HTML也有应该运行,因为它定义在HTML中使用JavaScript的功能,这似乎并没有使用该指令的情况发生。

However, the HTML also has JavaScript that should run, since it defines functions used in the HTML, and that doesn't seem to happen using the directive.

有一些角式的方式来做到这一点?还是需要摸索出来的带外脚本加载技术?

Is there some Angular-style way to do that? Or do I need to explore out-of-band script loading techniques?

(请让我们不讨论我是否应该信任服务器足以运行Java的脚本,它寄给我。我信任的服务器,我知道的风险,这是一个非常特殊的情况。)

(Please let's not discuss whether I should trust the server enough to run java-script it sends me. I do trust the server, I'm aware of the risks, and this is a very specialized situation.)

推荐答案

您需要的jQuery(前角加载它):

You need jQuery (load it before Angular):

我们看着在jqlite支持脚本标记,但需要做的事情得到一个跨浏览器支持什么涉及到很多的黑魔法。为此,我们决定,现在我们只是要建议用户使用jQuery的一起在这种情况下的角 -
<一href=\"https://groups.google.com/d/msg/angular/H4haaMePJU0/5seG803by5kJ\">https://groups.google.com/d/msg/angular/H4haaMePJU0/5seG803by5kJ

"we looked into supporting script tags in jqlite, but what needs to be done to get a cross-browser support involves a lot of black magic. For this reason we decided that for now we are just going to recommend that users use jquery along with angular in this particular case" -- https://groups.google.com/d/msg/angular/H4haaMePJU0/5seG803by5kJ

又见<一个href=\"http://stackoverflow.com/questions/12197880/angularjs-how-to-make-angular-load-script-inside-ng-include\">AngularJS:如何使内部角度负载脚本NG-包括哪些内容?

这篇关于插入HTML与要运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆