我可以像在 jQuery 的 $.ajax
中那样,在 Angularjs $http
中设置 context
吗?
define([
'app'
], function(app) {
app.controller("controller1", function($scope, $route, $http) {
return $http({
method: 'GET',
url: 'server.php'
}).then(function(response) {
$scope.contacts = response.data;
});
});
});
此外,在jQuery的$.ajax
中有更多回调函数,例如.done
、.promise
,我可以使用它们来操作context
,像下面这样,我想知道在Angularjs
中是否也能做到同样的事情?
$.ajax({
type: "GET",
dataType: "HTML",
url: 'server.php',
context: $("#container"),
async: true,
beforeSend: function() {
$(this).html('loading...');
},
success: function (returndata, status, jqxhr) {
$(this).html(returndata).hide().fadeIn();
},
}).fail(function() {
alert("error");
}).done(function(returndata) {
},
.always(function() {
alert("complete");
}
});
**
是用来做什么的吗? - Run**
什么都不是。它只是一个非常粗的行标记。$scope.$apply()
意味着$scope.IsShow=true
应用于 HTML。但这可能并不需要。 - Ramesh Rajendran