Javascript 角通过参数
我正在尝试学习AngularJs,下面的图片中显示了我正在观看的课程的代码。作者正在执行Javascript 角通过参数,javascript,angularjs,Javascript,Angularjs,我正在尝试学习AngularJs,下面的图片中显示了我正在观看的课程的代码。作者正在执行$http.get(“url”)。然后(函数()…。我不明白的是,onUserComplete函数接受response参数,但是在then函数中,他没有传递这个response参数,这个例子是有效的。根据我在JavaScript中的理解,我们应该这样做:then(onUserComplete(response))有人能告诉我吗 然后需要一个函数作为参数,这正是onUserComplete所要求的 在简单的语法
$http.get(“url”)。然后(函数()…
。我不明白的是,onUserComplete
函数接受response
参数,但是在then
函数中,他没有传递这个response
参数,这个例子是有效的。根据我在JavaScript中的理解,我们应该这样做:then(onUserComplete(response))有人能告诉我吗
然后需要一个函数作为参数,这正是onUserComplete
所要求的
在简单的语法中,您会看到:
.then(function (response) {
$scope.user = response.data;
});
更常见的是,使用匿名语法:
.then(response =>
$scope.user = response.data;
);
这就是它的全部内容。onUserComplete
只是一个替代品。这个。然后,
需要一个函数作为参数,这正是onUserComplete
的含义
在简单的语法中,您会看到:
.then(function (response) {
$scope.user = response.data;
});
更常见的是,使用匿名语法:
.then(response =>
$scope.user = response.data;
);
这就是它的全部内容。onUserComplete
只是一个替代品。然后
函数将用response(数据,实际上)对象调用您的回调。然后
函数将用response(数据,实际上)对象调用您的回调。然后()
函数以回调函数作为参数。回调函数存储在变量onUserComplete
中。因此,当作者编写时,然后(onUserComplete)
,onUserComplete
没有被调用,它只是作为引用传递。The。然后()
函数将回调函数作为其参数。回调函数存储在变量onUserComplete
中。因此,当作者编写时,则(onUserComplete)
,onUserComplete
未被调用,它只是作为引用传递。我建议您再次查看文档:$http
但长话短说:
。然后基本上等待承诺返回,这意味着服务器的响应到达
响应包括参数数据和来自服务器的数据(比如json)
然后是EXPECT函数作为参数,因此函数名是函数的替代项,在您的例子中,它是onUserComplete
看看类似的例子:
// Simple GET request example :
$http.get('/someUrl').
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
我建议您再看一遍文档:$http
但长话短说:
。然后基本上等待承诺返回,这意味着服务器的响应到达
响应包括参数数据和来自服务器的数据(比如json)
然后是EXPECT函数作为参数,因此函数名是函数的替代项,在您的例子中,它是onUserComplete
看看类似的例子:
// Simple GET request example :
$http.get('/someUrl').
success(function(data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
哦,好吧,我认为这是一个调用,这就是为什么我希望它传递参数,所以它将在调用时传递response
,而我不必传递它?哦,好吧,我认为这是一个调用,这就是为什么我希望它传递参数,所以它将在调用时传递response
,而我不必传递它?