我没有在浏览器Angular js上看到ng-repeat数据

时间:2017-02-17 11:34:24

标签: javascript angularjs view ng-repeat

出于某种原因,我没有在浏览器中可视化数据。

这是我的控制台的照片:

enter image description here

在p标签内部,我希望看到检索到的数据。

以下是观点:

<div class="row" ng-repeat="voce in voices">
    <p style="color:#000;">{{voce.series}}</p>
</div>

这是控制器:

app.controller('MainCtrl', function($scope,$q,voci) {

var promise = voci.getVoices();

promise.then(function(data){
    $scope.voices = data;
    console.log($scope.voices);
});

});

这是服务voci:

app.service('voci', function ($http,$q) {

var deferred = $q.defer(); 

$http.get('urldata.json').then(function(data)
{
    deferred.resolve(data);
});

this.getVoices = function(){
    return deferred.promise;
};

})

console.log $ scope.voices的输出:

enter image description here

我正在使用ngroute关联视图和控制器,在主模块中:

var app = angular.module('generaPreventivoApp', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize'
  ])

  .config(function ($routeProvider, $locationProvider) {

$routeProvider
  .when('/', {
    templateUrl: 'views/main.html',
    controller: 'MainCtrl',
    controllerAs: 'main'
  })
  .when('/about', {
    templateUrl: 'views/about.html',
    controller: 'AboutCtrl',
    controllerAs: 'about'
  })
  .otherwise({
    redirectTo: '/'
  });
   $locationProvider.hashPrefix('');
  });

为什么会出现这种问题?谢谢

1 个答案:

答案 0 :(得分:2)

尝试:

<div class="row" ng-repeat="voce in voices.data">
    <p style="color:#000;">{{voce.series}}</p>
</div>

或:

app.controller('MainCtrl', function($scope,$q,voci) {

var promise = voci.getVoices();

promise.then(function(data){
    $scope.voices = data.data;
    console.log($scope.voices);
});

});