在 ng-repeat 之外访问和绑定数据

Access and bind data outside of ng-repeat

我有一个 ng-repeat,它在下拉列表中重复一堆产品。

将鼠标悬停在这些人身上时,我想将悬停在下拉菜单外的容器中弹回图像。

标记:

<div class="quick-view-filters-container" ng-controller="setZoomDrop">
    <!-- zoomed image container from ng-repeat below -->
    <div class="product--shade__image-zoom--container">
        <img class="ng-hide" ng-show="zoom=1" image="option.product" step="1" always="1" />
    </div>
    <!-- dropdown -->
    <div class="product-select-shades-container" ng-repeat="attribute in attributes | onlyAttrsWithManyOptions | orderBy:$parent.$parent.$parent.configurableOrder">
        <h4>Products:</h4>
        <div class="product--options_list">
            <div ng-repeat="option in attribute.options" class="product--option_item" ng-if="option.product">
                <span class="product--shade__image ">
                      <!-- image -->
                      <img class="{{:: attribute.code == 'lamp_colour_config' ? 'zoomed' : ''}}" image="option.product" step="1" ng-mouseenter="setZoom(1)" ng-mouseleave="setZoom(0)" always="1" />
                    </span>
            </div>
        </div>
    </div>
</div>

控制器:

window.app.controller('setZoomDrop', ['$scope', function($scope) {

    var zoom = null;

    $scope.setZoom = function(number) {
        $scope.zoom = number;

    };
}]);

工作原理:

在您的 setZoom 函数中,如果 mouseenter 则传递选项对象而不是传递数字,如果 mouseleave 则传递 null:

$scope.curOpt = null;
$scope.setZoom = function(option) {
   $scope.curOpt = option;
}

然后在你的 html:

<img ng-show="curOpt" image="curOpt.product" step="1" always="1" />