2016-12-24 68 views
1

我有这个控制器...获取JSON数据到ioni视图

"use strict"; 

var app = angular.module('ng-laravel'); 
app.controller('StartCtrl',function($scope, $http,$rootScope,$ionicLoading,$cordovaDevice,$cordovaVibration,ionicToast,$ionicPlatform,$cordovaNetwork){ 
    $http.get('https://www.myurl.com/stringjson'). 
    success(function(data, status, headers, config) { 
     $scope.progetti = data.items; 
    }). 
    error(function(data, status, headers, config) { 
    // log error 
    }); 
}); 

是正确获取这样的JSON数据:

[{"id":2,"titolo":"The Marriage","descrizione":"Sal, a thirteen year old girl, narrates a story told 
by her Grandfather, which begins in a hospital room after Sal\u2019s Grandmother becomes ill during 
a road trip. The story of The Marriage Bed flashes back to small-town Kentucky, where Sal\u2019s grandparents 
first met. Gramps feels love at first sight for Gram, and courts her for the better part of a month 
before she accepts a marriage proposal. On the night of their wedding, Gramps and Gram find a special 
bed in their new home: the bed that had belonged to Gramps\u2019 parents, and the bed that they\u2019ve 
slept in all of their lives since. The tale ends with Sal wondering about her own romantic future. 
    ","inizio":"2016-12-17 00:00:00","fine":2016,"goal":10000,"banner":"1457196511-29619972.png","entry_by" 
:1,"created_at":"2016-03-05 17:48:31","updated_at":"2016-03-06 11:33:02","funded":"0","pledged":1000 
,"image":"","id_categoria":5,"staff_picked":null,"vetrina":null,"summary":"A young girl traveling with 
her Grandparents recounts a favorite family love story ","numero_finanziatori":2,"active":1,"tags":"" 
,"banner3":"","image2":"","image3":"","motivazione":"Vediamo se funziona","didascalia":"Prova prova" 
,"rating":5,"prima":0,"id_azienda":0,"banner2":""} 

这里是我的看法,在这里我无法显示数据...

<div class="hero no-header flat"> 
     <div class="content"> 
      <div class="app-icon"></div> 
      <h2 class="light">Welcome</h2> 
      <p class="stable">Our projects</p> 
     </div> 
    </div> 
    <ion-list> 
      <ion-item ng-controller="StartCtrl" class="item-avatar"> 
       <h2>{{ items[0].nome}}</h2> 
      </ion-item> 
     </ion-list> 
    <div class="padding"> 
     <button type="submit" class="button button-full button-assertive ink">{{ data.nome }}</button> 
     <button ui-sref="login" class="button button-full button-clear button-light">back to login</button> 

    </div> 
</ion-content> 

回答

0

您打印错误变量..

<ion-list> 
      <ion-item ng-controller="StartCtrl" class="item-avatar"> 
       <h2>{{ progetti[0].titolo}}</h2> 
      </ion-item> 
     </ion-list> 

试试这个.. 仅$scopethis变量自动同步。

+0

已经尝试previsiously ...不工作 – rubenSousa

+1

对不起,错误的变量:)它不是诺姆,但titolo – rubenSousa