sim*_*994 3 angularjs angular-http
我使用AngularJs,我需要在$ http.post连接后返回一个数据.这是代码:
app.controller('PrincipalController',['$http', '$scope', function($http,$scope){
$scope.myData = 0;
$http.post("server/checklogin.php",
{id: "id",email: "email",password: "password"}
)
.success(function(data){
console.log($scope.myData) //0
$scope.myData = data;
console.log($scope.myData); // 1
}
Run Code Online (Sandbox Code Playgroud)
OLD:如何将数据传递给myData? - 感谢您的回答,对不起,如果我没有解释清楚.
但现在,在HTML中,{{myData}}我能写些什么?
我不知道它是否是基础,但我必须使用"ng-if"来使用"myData".
编辑:谢谢!我想我已经解决了!:d
通常在您的服务中,您将返回承诺
myService.getCheckLogin = function {
return $http.post("server/checklogin.php",
{id: "id",email: "email",password: "password"}
);
}
Run Code Online (Sandbox Code Playgroud)
然后在控制器中
myService.getCheckLogin()
.success(function(data){
$scope.myData = data;
}
.error(function(err){
console.log(err);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25058 次 |
| 最近记录: |