AngularJS、mdList、ng-repeat 和生成器

AngularJS, mdList, ng-repeat and generators

发电机:

$scope.inside = [...];

var generator        = function*() {
    var l = Math.ceil($scope.inside.length / 3);
    for (var i = 0; i < 3; i++) {
        yield $scope.inside.slice(l * i, l * (i + 1));
    }
};
$scope.insideDivided = generator();

模板:

<md-list flex ng-repeat="column in [1,2,3]">
    <md-list-item ng-click="log(button.url)" ng-repeat="button in insideDivided.next().value">
        {{log(button)}}
        {{button.title}}
    </md-list-item>
</md-list>

说明{{log(button)}}将正确的项目写入控制台

Object {title: "someTitle1", url: "/inside/fake.html", $$hashKey: "object:13"} root.js:100 
Object {title: "someTitle2", url: "/inside/fake.html", $$hashKey: "object:14"} root.js:100 
Object {title: "someTitle3", url: "/inside/fake.html", $$hashKey: "object:15"}
....

但只创建空 <md-list>

    <!-- ngRepeat: column in [1,2,3] --><md-list flex="" ng-repeat="column in [1,2,3]" role="list" class="ng-binding ng-scope flex">

        <!-- ngRepeat: button in insideDivided.next().value -->
    </md-list><!-- end ngRepeat: column in [1,2,3] --><md-list flex="" ng-repeat="column in [1,2,3]" role="list" class="ng-binding ng-scope flex">

        <!-- ngRepeat: button in insideDivided.next().value -->
    </md-list><!-- end ngRepeat: column in [1,2,3] --><md-list flex="" ng-repeat="column in [1,2,3]" role="list" class="ng-binding ng-scope flex">

        <!-- ngRepeat: button in insideDivided.next().value -->
    </md-list><!-- end ngRepeat: column in [1,2,3] -->

为什么 ng-repeat 有效,但 create md-list-item 无效?

ng-repeat 不知道生成器。您需要先将其转换为数组并对其进行迭代。

这是 github 上的问题。 https://github.com/angular/angular.js/issues/15202

看来他们也不会很快得到支持。