Console screenshot我的代码出现问题;我在点击按钮时获得了值,并且控制台中也显示了相同的值。但是,我在输入字段中看不到相同的值。任何人都可以帮忙吗?
$scope.getFees = function (id) {
getClients.getFeesPoints(id).then(function(response) {
$scope.fees = response.data.fees;
console.log($scope.fees);
});
};
<input type="text" ng-model="fees" class="mdltb-inp fee-inp"
name="fees" placeholder="35$" >
检查图像30的链接是响应数据的值
答案 0 :(得分:0)
从代码中删除value="{{User}}"
并验证$scope.fees = response.data;
绑定文本值而不是对象。
如果response.data
是一个对象,则不会绑定到输入文本字段。从response.data
对象中找出适当的密钥,并使用该密钥绑定输入。此外,如果值未绑定,请在分配值
$scope.$apply()
答案 1 :(得分:0)
由于我没有足够的回购评论,所以发帖回答。您可以使用安全申请更新范围变量吗? https://coderwall.com/p/ngisma/safe-apply-in-angular-js
OR
您能否粘贴您从回复中获得的数据?所以我可以清楚地知道你想要存储什么。
答案 2 :(得分:0)
我这样你应该这样试试
var app = angular.module("myapp", []);
app.controller("myCtrl", ['$scope', function($scope) {
$scope.fees="new";
$scope.getFees = function (id) {
//getClients.getFeesPoints(id).then(function(response)
//{
$scope.fees = 50;
console.log($scope.fees);
//});
};
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myapp">
<div ng-controller="myCtrl">
<input type="text" class="form-control" id="inputValue" name="uservalue" ng-model="fees" ng-required="true" autofocus="true" ng-blur="checkIfValid()"/>
<button ng-click="getFees(true)">Demo</button>
<h1>{{fees}}</h1>
</div>
</div>
答案 3 :(得分:0)
我已经通过使用$ rootScope解决了这个问题,即&#34; $ rootScope“是在网页中创建的所有”$ scope“角对象的父对象。