roger nm
roger nm

Reputation: 277

how to display data in input field using angular js

First off all, I want to show the json data from my codeigniter controller in view page through $http post method.

The problem is that I'm facing some problems, then I can't make it works.

Code:

.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'
       ]
     });
   }]
 }
})

Controller:

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

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

CI controller

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

View:

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

Upvotes: 1

Views: 3924

Answers (1)

Mohan Gopi
Mohan Gopi

Reputation: 7724

Upadate with the my answer i will work

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);
   });
 });

View:

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

Upvotes: 1

Related Questions