首先,Angular 也使用 jQuery。(jQuery 精简版)
来自常见问题
Angular 是否使用 jQuery 库?
是的,如果在引导应用程序时,Angular 存在于您的应用程序中,则 Angular 可以使用 jQuery。如果 jQuery 没有出现在你的脚本路径中,Angular 会退回到它自己的 jQuery 子集实现,我们称之为 jQLite。
但是,我认为您在这里不需要完整的 jQuery 函数。
这就是我所做的。
我使用指令并将 html 作为模板并将替换设置为 true。
jsFiddle
<myhtml></myhtml>
angular.module('myApp', []).directive('myhtml', function($http) {
return {
restrict: 'E',
scope: {},
template:'',
link: function(scope, element, attrs) {
$http.post('/echo/json/', data).success(function(re) {
element.html(re.html);
});
}
}
});
编辑说明:
我只是更新了 jsFiddle。
我在顶部包含 jquery 以在 jsFiddle 中回显请求。实际上,你不需要那个。
但是,它向您展示了您可以在 Angular 中使用 jQuery。
如果您的 html 不包含任何 angular 标签,则此示例应如您所愿。
否则,您需要使用compile而不是link。