2016-11-13 121 views
1

我在Ionic中使用有角度的UI路由器来构建应用程序,但是我的一个页面news.html没有加载内容。它显示视图标题但不显示离子内容中的内容,该页面为空白。 这个代码是一个模板news.html离子视图无法加载内容

<ion-view view-title="news"> 
    <ion-content> 
    <div class="list card" ng-repeat="item in articles"> 
     <div class="item item-thumbnail-left item-text-wrap"> 
     <h2 class="post-title">{{item.name}}</h2> 
     <p class="post-author">{{item.description}}</p> 
     </div> 
    </div> 
    </ion-content> 
</ion-view> 

在app.js我已经添加了以下UI航线代码

.config(function($stateProvider, $urlRouterProvider) { 
$stateProvider 
    .state('index', { 
     url: '/', 
     templateUrl: 'templates/home.html', 
     controller: 'mainCtrl' 
    }) 
    .state('news', { 
     url: '/news', 
     templateUrl: 'templates/news.html', 
     controller: 'newsCtrl' 
    }); 

$urlRouterProvider.otherwise('/'); 
}) 

的内部,我newsCtrl是

.controller('newsCtrl',function($scope, $http){ 
    $http.get('https://newsapi.org/v1/articles?source=the-next-web&sortBy=latest&apiKey=4ff16a30e00640cab0a2a9731ccc9510').success(function(data){ 
     $scope.articles = data.sources; 
     console.log('news control'); 
    }); 

回答

0

相同的代码作品

carService.controller('newsCtrl', ['$scope', '$http', function($scope, $http) { 
    $http.get('https://newsapi.org/v1/sources?language=en').success(function(data) { 
    $scope.articles = data.sources; 
    console.log(data); 
    console.log('news control'); 
    }); 

}]); 

DEMO