1

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>
7
  • ng-model="data1", it should be like this Commented Jul 14, 2016 at 4:47
  • i want display name only from json data Commented Jul 14, 2016 at 4:51
  • What do you get when you console.log(response)? Commented Jul 14, 2016 at 4:51
  • ReferenceError: reponse is not defined Commented Jul 14, 2016 at 4:54
  • Where did you put this console.log(response)? Commented Jul 14, 2016 at 4:55

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

2 Comments

how can you display all the name of your array inside a input field
@rogernm do you want to view the name of your array inside a list or option that is possible how in input field

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.