0

I have a set of files in a server which I am looping though and constructing a JSOn and saving it as a separate file. I am using python for this. Works quite well. Now the scope is the number of files in the directory will increase/ change throughout the day..and I am running the script every 10 min to rewrite the json...the file name stays same and i am calling it in a single page html document using angular.js..Again fairly simple...But now I am having problem when the JSON is changing I am not seeing any change on the page unless I reload the page. Could I do something about this?

With angular I am using

$http('something.json').success(callback function with some argument data)

and in the markup something like

<ul>
<li ng-repeat="x in data">{{x.id}}</li>
</ul>
2
  • Looks similar to this: stackoverflow.com/q/18416458/1444541 Commented Jan 16, 2015 at 1:41
  • @JaKXz--well...if I really want to set time interval it would be fairly easy. I am wondering if I could do without that and work with an idea of a listener which responds to the change. Could that be possible? Commented Jan 16, 2015 at 1:45

1 Answer 1

1

Your call to $http is one-time operation which happens after page load like this:

$http('something.json').success(function(data){
    $scope.data = data;
});

  • angular is kickstarted
  • ng-controller containing $http request is evaluated and request for 'something.json' is sent
  • ...
  • when your json arrives, your success function is called with data from json
  • view (html template) is updated with new data

Angular keeps your model (eg $scope.data) and UI (expressions in template) up to date, but it doesn't update external resources. If you want to periodically poll for changes in 'something.json' you can use $timeout service as suggested in JaKXz's comment.

Sign up to request clarification or add additional context in comments.

1 Comment

@josef--that's exactly what I was looking for. Thanks for explaining this. Really appreciate it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.