$ scope不想更新

时间:2017-08-21 11:58:01

标签: angularjs scope angularjs-scope

我在更新$ scope时遇到问题。我以前遇到过问题,但是$ apply会让一切都成功。现在我不知道该怎么办。 $ scope.sensor不会更新。 JSON数据从服务器下载,但不会更新$ scope。这是我的代码(更新):

app.controller('scheme', function($scope, $http, $timeout) {

$scope.showinfo = function(sensor, $event) {

    var info = document.querySelector("#info");

    if (info.style.opacity == 0) {

            $http.get("http://www.hbmedia.pl/client/zgazowarka/json2.php?module=sensor&code="+code+"&sensor="+sensor).then(function(response) {
                $scope.sensor = response.data;
                $scope.$digest();
                console.log($scope.sensor);
            });

            info.style.top = parseFloat($event.target.style.top.replace(',', '.')) + "%";
            info.style.left = parseFloat($event.target.style.left.replace(',', '.')) + "%";
            info.style.opacity = 1;

    } else {

        info.style.opacity = 0;

    }
}

refresh();
});


<strong>{{ sensor.name }}</strong>
<span>{{ sensor.code }}</span>
<p>{{ sensor.min }}-{{ sensor.max }}</p>

0 个答案:

没有答案