【发布时间】:2018-12-30 13:19:13
【问题描述】:
我正在尝试使用 ng-model 将我的 Controller 的对象值绑定到输入,如果我添加它 ng-repeat 它是绑定数据,但如果我直接调用它,它不会将数据绑定到输入。谢谢你:)
角度控制器
SMSApp.controller('studentUpdateController', function ($scope, $routeParams, GetStudentService) {
$scope.stuid = $routeParams.STUDENTID != null ? $routeParams.STUDENTID : 0;
GetStudentService.getbyId($scope.stuid).then(function (result) {
$scope.obj = JSON.parse(result);
$scope.obj = $scope.obj.Table;
console.log($scope.obj);
});
});
控制台日志
HTML 代码
<div class="col-md-4 form-group">
<label>First Name</label>
<input type="text" class="form-control" ng-model="obj.FIRSTNAME" placeholder="First Name" required />
</div>
<div class="col-md-4 form-group">
<label>Middle Name</label>
<input type="text" class="form-control" ng-model="obj.MIDDLENAME" value="" placeholder="Middle Name" required />
</div>
【问题讨论】:
-
控制台输出显示它的一个数组。将
$scope.obj.Table更改为$scope.obj.Table[0]。 -
永远欢迎朋友。
标签: angularjs json dom data-binding angular-ngmodel