AngularJs 如何用controller里面的数据来构建ng-repeat (非$scope)?

View 里面可以这样拿到 Controller里面的数据

<h1>{{vm.songs[1].title}}</h1>

但这样就不行

<h1 ng-repeat="x in songs">{{x.title}}</h1>

Controller 代码如下

(function() {

  angular
    .module('meanApp')
    .controller('songCtrl', songCtrl);

  function songCtrl($location,meanData) {

      var vm = this;
      vm.songs = [
          {title : "foo", singer: "bar", code: "abc-def"},
          {title : "hello", singer: "world", code: "123-456"}
      ];

  };

})();

求解? 谢谢

阅读 1.9k
2 个回答

<h1 ng-repeat="x in vm.songs">{{x.title}}</h1>

如果用的不是$scope,那么就需要把前面的变量名带出来,只有$scope能在html中能省略。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题