申请后滑块未更新

时间:2016-06-06 14:52:09

标签: javascript angularjs

我有一个包含视图信息的对象模型。当我对这个对象进行一些更改然后我使用apply时,每个组件都会更新滑块。我只能在窗口调整大小后才能看到滑块更新。有什么想法吗?

$rootScope.$on('newPrintSelected', function (event, selectedPrinter) {
        StorageModule.storage.find(collectionName, {_id : selectedPrinter.printer_hardware._id}, function(error, data){
            if (error) { //Not Found
                console.error("Ops. There is something wrong with this action...");
            }else {
                    if(data[0].printOptions == null){
                        $scope.options = angular.copy($scope.default);
                        $scope.options.layerThickness = 30 - ($scope.options.layerThickness * 100);
                        $scope.persistedOptions = angular.copy($scope.default);
                        $scope.persistedOptions.layerThickness = 30 - ($scope.persistedOptions.layerThickness * 100);
                    }else{
                        data[0].printOptions.layerThickness = 30 - (data[0].printOptions.layerThickness * 100);
                        $scope.options = angular.copy(data[0].printOptions);
                        $scope.persistedOptions = angular.copy(data[0].printOptions);
                    }
                }
                $scope.selectedPrinterHardware = angular.copy(data[0]);
                console.warn($scope.options);
                $scope.$apply();
            });
    });

滑块:

<div class="slider">
   <rzslider rz-slider-model="options.infill" rz-slider-options="slider.infill">

    </rzslider>
</div>

$ scope.options是用作模型的对象。 console.warn($ scope.options);表明对象是正确的。

修正:

setTimeout(function(){ $scope.$broadcast('rzSliderForceRender'); }, 25);

每次出现Slider时都会显示。

这是在文档上。对不起,我很抱歉。

1 个答案:

答案 0 :(得分:1)

播放刷新事件怎么样:

$scope.refreshSlider = function () {
  $timeout(function () {
    $scope.$broadcast('rzSliderForceRender');
  });
};

Reference 1 Reference 2