Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 刷新范围变量更改的数据_Angularjs_Angularjs Scope_Watch - Fatal编程技术网

Angularjs 刷新范围变量更改的数据

Angularjs 刷新范围变量更改的数据,angularjs,angularjs-scope,watch,Angularjs,Angularjs Scope,Watch,我正在使用AngularJS进行外部web项目。 我被页面的更新间隔所困扰,因为我从页面内部的html div获取JSON数据,JSON数据是从策略发送的。 我正在使用 $scope.json_data = angular.element(document).find('#idofthejsondiv').html(); div每“x”秒获得不同的JSON数据 如何更新有关divs值更改的页面?尝试以下操作: $scope.$watch ( function () {

我正在使用AngularJS进行外部web项目。
我被页面的更新间隔所困扰,因为我从页面内部的html div获取JSON数据,JSON数据是从策略发送的。 我正在使用

$scope.json_data = angular.element(document).find('#idofthejsondiv').html();
div每“x”秒获得不同的JSON数据

如何更新有关divs值更改的页面?

尝试以下操作:

$scope.$watch (
    function () {
        return angular.element(document).find('#idofthejsondiv').html();
    },
    function (newValue) {
        console.log (newValue);
        // do stuff with the new value...
    }
);

但必须提到的是,这似乎不是一个合适的应用程序结构。div中的数据必须通过某种服务在某处进行更改。更好的方法是在该服务将更改放入div时拦截该服务,并对该新内容执行任何您想要的操作

我不确定,但您可以尝试:$scope.$watch('json_data',function(){//code});你能澄清一下div的内容是如何变化的吗?这是通过angular还是其他框架实现的?