如何使用角度js在输入字段中显示数据

时间:2016-07-14 04:46:21

标签: angularjs codeigniter

首先,我希望通过codeigniter方法在controller页面中显示view $http post的json数据。

问题是我遇到了一些问题,然后我无法使其发挥作用。

代码:

.state('GetData', {
 url: "/getdata",
 templateUrl: base_url + "loadl/getdata",
 data: {
   pageTitle: 'Datapage'
 },
 controller: "Mycontroller",
 resolve: {
   deps: ['$ocLazyLoad', function($ocLazyLoad) {
     return $ocLazyLoad.load({
       name: 'Myapp',

       files: [

         base_url + 'application/assets/js/controllers/Mycontroller.js'
       ]
     });
   }]
 }
})

控制器:

angular.module('Myapp')
 .controller('Mycontroller', function($rootScope, $scope, $http, $timeout) {

   $http.get(base_url + "getData/show").
   success(function(response) {
     $scope.data1 = response.data;
   });
 });

CI控制器

public function show() {
  echo '{"data":[{"sl_num":"1","name":"James","category":"1"}]}';
}

查看:

<div class="form-group">
  <label class="control-label">Name</label>
  <input type="text" placeholder="John" class="form-control" ng-model="data1.name" />
</div>

1 个答案:

答案 0 :(得分:1)

根据我的回答,我会工作

angular.module('Myapp')
 .controller('Mycontroller', function($rootScope, $scope, $http, $timeout) {
   $http.get(base_url + "getData/show").
   success(function(response) {
     console.log(response);
     $scope.data1 = response.data[0].name;
     console.log($scope.data1);
   });
 });

查看:

<div class="form-group">
  <label class="control-label">Name</label>
  <input type="text" placeholder="John" class="form-control" ng-model="data1" />
</div>