roger nm roger nm - 4 months ago 18
AngularJS Question

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>

Answer

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>