2016-12-24 72 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