Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS:为什么不是';我的ng模型更新了吗?_Angularjs - Fatal编程技术网

AngularJS:为什么不是';我的ng模型更新了吗?

AngularJS:为什么不是';我的ng模型更新了吗?,angularjs,Angularjs,在这段代码中,我成功地从服务器获得了响应,但似乎无法获得要显示在ng模型中的值 我尝试了各种方法来访问对象,但认为语法object.attribute是正确的。我弄错了吗 <html ng-app="notesApp"> <head><title>Notes App</title></head> <body ng-controller="MainCtrl as ctrl"> <div> <h2>

在这段代码中,我成功地从服务器获得了响应,但似乎无法获得要显示在ng模型中的值

我尝试了各种方法来访问对象,但认为语法object.attribute是正确的。我弄错了吗

<html ng-app="notesApp">
<head><title>Notes App</title></head>
 <body ng-controller="MainCtrl as ctrl">
<div>
   <h2>Job Inspections?</h2>


<div class="input-group">
    <label>Inspection ID</label>
    <input type="text" ng-model="ctrl.list.id">
</div>
<div class="input-group">
    <label>Inspection ID2</label>
    <input type="text" ng-bind="ctrl.list.id">
</div>
<div class=
<div class="input-group">
    <label>Job ID</label>
    <input type="text" ng-model="ctrl.list.job_id">
</div>
<div class="input-group">
    <label>Inspection Type</label>
    <input type="text" ng-model="ctrl.inspection_type">
</div>
<div class="input-group">
    <label>Bodywork</label>
    <input type="checkbox"
           ng-checked="ctrl.bodywork === 1">
</div>
<div class="input-group">
    <label>Lighting</label>
    <input type="checkbox"
           ng-checked="ctrl.lighting === 'YES'">
</div>

 </div>

<script
  src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.js">
</script>
<script type="text/javascript">
 angular.module('notesApp', [])
.controller('MainCtrl', ['ItemService', function(ItemService) {
var self = this;
self.list = function() {
  return ItemService.list().then(function(data) {

    console.log(data);
    return data;
    })
}();

//console.log(self.list);
self.add = function() {
  ItemService.add({
    id: self.list().length + 1,
    label: 'Item ' + self.list().length
  });
};

  }])
  .factory('ItemService', ['$http', function($http) {




return {
    list: function() {

        return $http.get('/api_job_inspections/1/edit').then(function(response) {
                    return response.data;
                  }, function(errResponse) {
                    console.error('Error while fetching notes');
                  });

        },
      add: function(item) {
        self.items.push(item);
      }
    };

}]);

</script>
</body>
</html>

Notes应用程序
工作检查?
检查ID
检查ID2

每次操作数据时,都应更新回调函数中的对象:

return ItemService.list().then(function(data) {
    self.list = data;
})
还要确保
数据
符合您的预期