ng-repeat没有显示我的工厂

时间:2016-08-28 17:58:34

标签: angularjs ionic-framework angular2-directives

我无法从工厂获得一些数据:

.factory("userDataFactory", function(){

    var user;
    var user_notes;

    var interfaz = {
      getUsuario: function(){
        return user;
      },
      getNotes: function(){
        return user_notes;
      },
      nuevoUsuario: function(userId, email){
          user = [userId, email];
      },
      addNotes: function(notes){
          user_notes = notes;
      }
    }

    return interfaz;
})

我首先要使用以下代码使用Ruby Api中的数据填充工厂:

$http({
            method : "POST",
            url: "http://localhost:3000/api/v1/checkuser",
            data: json
          }).then ( function mySucces(response){

              userDataFactory.nuevoUsuario(response.data.user[0].id, response.data.user[0].email);
              userDataFactory.addNotes(response.data.notes);
              $state.go('thirdday');

后来我用一个新的控制器叫我的工厂:

.controller('ListNotes', function($scope, userDataFactory, $state){

  $scope.notes = userDataFactory.getNotes();
  console.log($scope.notes);
  //console.log($scope.notes[0].note1);
})

最后,尝试在我的html(listnotes.html)中显示它

<div class="list">

    <a class="item" href="#" ng-repeat="x in notes">
        {{ x.note2 }} 

    </a>
</div>

我的路线配置以防万一:

.state('list',{
    url: '/listnotes',
    templateUrl: 'templates/listnotes.html',
    controller: 'ListNotes'
  })

所以,我错过了什么?为什么没有显示我从API获得的所有笔记?

提前致谢

修改

从我的API获取数据后,我转到“thirdday.html”视图,我只需按一个按钮即可转到列表视图。

  .state('thirdday',{
    url: '/thirdday',
    templateUrl: 'templates/thirdday.html',
    controller: 'Notes'
  })

2 个答案:

答案 0 :(得分:0)

在您的工厂&#39; user_notes&#39;包含带键的对象&#39; note1&#39; (根据您的日志声明console.log($scope.notes[0].note1))。并在ng-repeat中使用x.note2。设为x.note1

答案 1 :(得分:0)

尝试在html中添加注释{{notes}}。看看它是否有价值。 可能你只是没有在标记中添加ng-app或ng-controller或某些东西

相关问题