angularjs - 没有得到对 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>
解决方案
如果响应没有问题,请尝试添加$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);
});
}
推荐阅读
- python - 无法通过 Anaconda 安装 pygame
- php - mysql - 将查询字符串(如文本)插入数据库列
- c++ - 从 C++ 中的数字中删除尾随零
- javascript - 我需要 keith-wood 关于 jquery.countdown.js 的帮助
- c# - 字段初始值设定项不能引用 loginController 中的非静态字段、方法或属性
- reactjs - multipart/form-data 不适用于 apisauce
- java - Spring Boot RESTful API 层的设计及其实体映射
- matlab - 优化像素坐标并从一个点跟踪到另一个点以在 MATLAB 中计算曲折度
- javascript - React Typescript 如何发送道具并在子组件中使用它
- domain-driven-design - CQRS 读取模型预测:数据转换太复杂有多复杂