在angularjs中填充范围的文本输入

时间:2016-04-27 10:09:28

标签: angularjs

我有一个表单中的文本输入,我想填写我从承诺中获得的数据。

这是我的文字输入:

<input type="text" name="lastname" id="lastname" class="form-control input-lg"
ng-model="candidature.lastname"
required>

在我的控制器中我有这个:

candidatureService.get({id: $rootScope.username}).$promise.then(function (res) {

      $scope.candidature = {};
      $scope.candidature.lastname = res.nom;

//code...

}).catch(function (err) {
      console.log('Error getting data');
});

当我使用batrang检查我的应用程序时,我可以看到candidature中的对象$scope具有我正在使用该承诺的值:

enter image description here

正如您所见,我有ng-model="candidature.lastname"

有谁知道为什么文本输入没有从范围中获取值?

提前致谢。

1 个答案:

答案 0 :(得分:1)

在发出API请求之前尝试声明$scope.candidature = {}; ...

但是从代码中看起来您只声明了$scope.candidature.lastname而不是$scope.candidature.firstname

相关问题