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 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 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.
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));
});
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With