jQuery .load()等效于AngularJS [英] jQuery .load() equivalent AngularJS
问题描述
在jQuery中是否有一个等同于 $。load()
的AngularJS?我希望能够从另一个域提取(即在一个域上发布应用程序,但从一个完全独立的地址加载内容)。
Is there an AngularJS equivalent to $.load()
in jQuery? I want to be able to pull from another domain (i.e. post the app on one domain, but load content from a completely separate address).
推荐答案
jQuery的使用方法并不适合Angular,你不会在那里找到 load
等等(你显然可以使用jQuery而不是jqLite,如果你想要它)。
jQuery methods of usage don't really fit Angular, you won't find load
equivalent there (you obviously can use jQuery instead of jqLite if you want it badly).
Angular建议使用 ngInclude 指令。否则,您需要创建自己的指令并将结果从 $ http
请求写入元素,尤其是在需要更多控制的情况下。
Angular proposes the usage of ngInclude directive for similar off-hand scenarios. Otherwise you need to make your own directive and write the result from $http
request to element, especially if you need more control.
如果你想从特定的div中获取内容,你需要加载jQuery才能在响应时使用选择器,这样的东西就等于 load
:
If you want to 'get content from a particular div', you will need to have jQuery loaded anyway to use selectors on response, something like this would be an equivalent for load
:
app.directive('load', function ($http, $compile) {
return {
link: function (scope, element, attrs) {
$http.get('link.htm').success(function (response) {
var contents = angular.element("<div>").html(response).find("#someelement");
element.empty().append($compile(contents)(scope));
});
}
}
});
这篇关于jQuery .load()等效于AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!