md-slider在从控制器更新其模型值时不更新

时间:2017-01-06 12:34:37

标签: angularjs angularjs-material

我的HTML代码包含md-slider

<body ng-app="ABC">

    <div class="ctrl" ng-controller="mainCtrl">

    <md-slider ng-model="threshold" md-discrete min="1" max="100" aria-label="threshold"></md-slider>

    </div>
</body>

这是我的控制者:

angular.module("ABC", ["ngMaterial"])
       .controller("mainCtrl", function ($scope) {

    $scope.threshold = localStorage.getItem("myExtThreshold");
});

当我使用鼠标滑动滑块时,threshold会在控制器中更新。但是,当我在控制器中更改threshold时,滑块位置不会改变。例如,如果我将threshold值从20更改为60,并且我使用console.log($scope.threshold),则显示的值将为60,但md-slider仍为20。

localStorage.getItem("myExtThreshold")返回有效的数值。

1 个答案:

答案 0 :(得分:1)

在控制器中尝试此操作。当然你的代码没有错。只是将返回值设为数字

$scope.threshold = JSON.parse(localStorage.getItem("myExtThreshold"))