返回数据未从控制器显示

时间:2015-10-28 17:58:54

标签: javascript html angularjs

我可以从远程服务器获取数据,当我在视图页面上传递不显示时,我没有到达我在视图页面中出现问题或传递数据的位置?

控制台中的输出数据是:

[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
0: Object
email: "try.tr@xyz.com"
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

控制器

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>

1 个答案:

答案 0 :(得分:2)

您将其分配给var myVal,而不是将其分配给$scope.myVal。要查看Angular 2 way绑定魔法,您需要将值分配给$scope变量而不是javascript variable

同样返回$scope.myVal没有意义,只有分配就足够了。

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