Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用ionic和angularjs查看列表中数组中的数据_Angularjs_Ionic Framework - Fatal编程技术网

如何使用ionic和angularjs查看列表中数组中的数据

如何使用ionic和angularjs查看列表中数组中的数据,angularjs,ionic-framework,Angularjs,Ionic Framework,我在数组中推送数据没有问题,这是我的代码。当我在函数外部使用console.log(产品)时,我得到的是一个空数组,但当我在控制器内部使用console.log(产品)时,我得到的是我的数据 angular.module('ob3App.lead') .controller('LeadProductCtrl',['$scope','$http', function($scope,$http) { $scope.namegetfunction = function() {

我在数组中推送数据没有问题,这是我的代码。当我在函数外部使用console.log(产品)时,我得到的是一个空数组,但当我在控制器内部使用console.log(产品)时,我得到的是我的数据

angular.module('ob3App.lead')
    .controller('LeadProductCtrl',['$scope','$http', function($scope,$http) {

    $scope.namegetfunction = function() {

    var products=[];

        $http.get("http://5.9.42.45:8080/easycloud1/org.openbravo.service.json.jsonrest/Product?l=saiy5k&p=saiy5k")
        .success(function(response) {
        console.log(response);
        $scope.names = response.response.data;
        console.log($scope.names.length);

        $scope.names.forEach(function(item) {
          console.log(item.name);
          products.push(item.name);
        })

        console.log(products);

        })
        .error(function(responses){
            alert('error');
        });
    };
    $scope.namegetfunction();

 }]);
当我尝试使用ng repeat时,我无法在列表中查看它,我不知道我做错了什么

<ion-view>
    <ion-header-bar class="bar bar-header bar-positive flat">
        <button class="button button-positive" ng-click="back()"><i class="ion-arrow-left-c"> </i></button>
        <h1 class="title">Products</h1>
    </ion-header-bar>
    <ion-content>

        <ul class="list">
            <li class="item" ng-repeat="i in products" ui-sref="leadProduct" >
             <div>{{i}}</div>
            </li>
        </ul>

    </ion-content>
</ion-view>

产品
  • {{i}

上面的代码是以列表格式查看我的姓名,但我正在努力找出我做错的地方

您没有
$scope.products
,当您使用
ng repeat=“i in products”
时,AngularJS会在这里查找它,您拥有的是:

var products = [];
...
products.push(...)
这还不够,你必须把它分配给作用域,你必须这样做

$scope.products = products
当您完成数据收集,或直接从一开始就在范围内初始化数据时,例如

$scope.products = [];
$scope.names.forEach(function(item) {
      $scope.products.push(item.name);
})

您使用的是
console.log(products)
而不是
$scope.products
,这可能会让您觉得一切正常:)

看起来您在这一次“ng repate”中有一个输入错误正确的是“ng repate”是的,我已经纠正了这一点,但仍然是相同的结果,请看您在html{{products | json}中得到的结果