刷新有关范围变量更改的数据

Refresh data on change in scope variable

我正在使用 AngularJS 进行外部网络项目。
我坚持页面的更新间隔,因为我得到的 JSON 数据来自页面内部的 html div,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 进行更改时拦截此服务,并使用新内容

做任何你想做的事