在某些其他范围对象的 ng-repeat 中使用另一个范围对象值

Using another scope object values within the ng-repeat of some other scope object

我已经设置了一个fiddle来很好地解释我的问题。我想显示 $scope.gem 中的 ng-repeat 中的名称 [每个 ng-repeat 只有一个名称,并且不要全部循环] $scope.knobItems 而不扩展 knobItems范围。我希望通过保持控制器现在的确切结构来实现这一点。我是 angular 的新手。我只想知道这在 angular 中是否可行,是否是一个好的做法。

查看

<div ng-app="myapp">
    <div ng-controller="Mycont">
        <div ng-repeat="knobs in knobItems">
            <div ng-repeat="(key, value) in knobItems.nums">{{value.knobTitle}} : {{value.knobColor}}
                <div ng-bind="gem[0].name"></div>
            </div>
        </div>
    </div>
</div>  

控制器

var ngMod = angular.module("myapp", []);
ngMod.controller("Mycont", function ($scope) {
    $scope.knobItems = {};
    $scope.knobItems.nums = [{
        knobTitle: "Company Profile",
        knobColor: "#f46607"
    }, {
        knobTitle: "Deals left This Month",
        knobColor: "#ffcc00"
    }, {
        knobTitle: "Pricelist",
        knobColor: "#f40787"
    }, {
        knobTitle: "Pictures",
        knobColor: "#a1b80a"
    }, {
        knobTitle: "Videos",
        knobColor: "#14b9d6"
    }];
    $scope.gem = [{
        name: "Thomas"
    }, {
        name: "Sebastian"
    }, {
        name: "June"
    }, {
        name: "Yuvan"
    }];
});  

预期产出

你 fiddle 的输出与没有第一个 ng-repeat 完全相同:http://jsfiddle.net/2nrbrfxL/

根据你的描述而不是你的代码:

<div ng-app="myapp">
    <div ng-controller="Mycont">
        <div ng-repeat="knobs in knobItems">
            <div ng-repeat="(key, value) in knobs">{{value.knobTitle}} : {{value.knobColor}}
                <div ng-repeat="gemItem in gem">{{gemItem.name}}</div>
            </div>
        </div>
    </div>
</div>  

http://jsfiddle.net/p2fuq2du/

轻松修复:fiddle

<div ng-app="myapp">
    <div ng-controller="Mycont">
        <div ng-repeat="knobs in knobItems">
            <div ng-repeat="(key, value) in knobItems.nums">{{value.knobTitle}} : {{value.knobColor}}
                <div ng-bind="gem[$index].name"></div>
            </div>
        </div>
    </div>
</div>
    <div ng-app="myapp">
        <div ng-controller="Mycont">
             <div ng-repeat="(key, value) in knobItems.nums">{{value.knobTitle}} : {{value.knobColor}}
                 <div ng-bind="gem[key].name"></div>
             </div>
        </div>
    </div>