user3752338
user3752338

Reputation:

Return data is not displaying from controller

I am able to fetch the data form remote server and when I pass its not displaying on view page, i am not getting where I am having issue in view page or passing the data?

The output data in console is :

[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
0: Object
email: "[email protected]"
employee_id: 1442
grade: 11
name: "prett"
__proto__: Object

1: Object

2: Object

3: Object

4: Object

5: Object

6: Object

7: Object

8: Object

9: Object

controller

angular.module('myApp')
        .controller('searchCtrl', ['$scope', '$http', '$state','$stateParams','SeacrhResult', searchCtrl]);

        function searchCtrl($scope, $http, $state, $stateParams, SeacrhResult) {

        if ($stateParams.searchVal) {
            $scope.search_Val =  $stateParams.searchVal;
          } else {
            $scope.errmsg = "There are no results to be displayed";
          }
                   SeacrhResult.Search_values.query({val: $scope.search_Val}).$promise.then(function(response){
              var myVal =  response.hits.hits.map(function(items){
                return items._source;
              });
             console.log(myVal);
             return $scope.myVal; 
            }, function (error) {
                console.log("error");
            });
        }

html

<md-content class="tabsdemoDynamicHeight" ng-controller="searchCtrl" flex>
    <md-tabs md-dynamic-height md-border-bottom md-stretch-tabs="always end"  class="md-primary md-hue-2">
<md-tab label="Team">
        <md-content class="md-padding" flex>

          <h3 class="">People at ABC</h3> 
            <md-list flex layout="column">

              <md-subheader class="md-no-sticky">1234 results found</md-subheader>
              <md-list-item class="md-3-line" ng-repeat="item in myVal">

                <div class="md-list-item-text" layout="column" >

                  <h3><a  class="md-accent" href="#">{{ item.name }}</a></h3>

                </div>
              </md-list-item>
              <md-divider ></md-divider>
            </md-list>
            <p> asd as d asd as d </p>
        </md-content>
      </md-tab>
</md-tabs>
<md-content>

Upvotes: 1

Views: 81

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136184

You were assigning it to var myVal instead of assigning it to $scope.myVal. To see the Angular 2 way binding magic you need to assign the value to $scope variable rather than javascript variable.

Also returning $scope.myVal doesn't make sense, only assignment is enough.

$scope.myVal =  response.hits.hits.map(function(items){
     return items._source;
});

Upvotes: 2

Related Questions