首页 > 解决方案 > 没有得到对 html 视图页面的响应

问题描述

我在 angular js ui-router 中调用节点 js 的 api,但我的 $scope 函数没有得到对 html 视图页面的响应。

.state('statetwo', {
            url: '/statetwo',
            templateUrl: appHelper.templatePath('tables/basic')

        })

这是我的控制器

app.controller('formController', function ($scope,$http) {


    $scope.alldata=function(form)
    {
        let dataObj=JSON.stringify(form);
        alert(dataObj);



        $http.post("http://localhost:4000/login",dataObj)
            .then(function (response) {
            $scope.getdata2=response.data;
            console.log($scope.getdata2);
            //  let dataObj1=JSON.stringify($scope.getdata);
            //  $scope.data=dataObj1;
            //    console.log(dataObj1);
            })

        }
});

这是我在 html 页面中的 html 视图

<p>{{getdata2.Result}}</p>

标签: angularjsnode.js

解决方案


如果响应没有问题,请尝试添加$scope.$apply()

每当有一项任务需要花费一些时间时,有时需要调用 Angular 来强制更新您的绑定。

如果响应中有问题,您可以在控制台中看到它。

$http.post("http://localhost:4000/login",dataObj)
     .then(function (response) {
        $scope.getdata2=response.data;
        $scope.$apply();
     }).catch(function(error) {
        console.log(error);
     });
}

推荐阅读