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

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"}
      ];

  };

})();

求解? 谢谢


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


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

【热门文章】
【热门文章】