0

I have a jsbin setup here http://jsbin.com/esofiq/1/edit I'm getting confused by the way I think angularjs should work, I have some json data attached to a data attribute, angularjs fetches the data and creates the view. Doesn't calling $scope.mydata within the controller set 'mydata' as the model, and shouldn't it now update the view if the data within the data attribute is changed?

Is this easier to achieve in other frameworks if this isn't appropriate for angular?

Community
  • 1
  • 1
raphael_turtle
  • 7,154
  • 10
  • 55
  • 89

2 Answers2

0

I think these two will give you the idea:

How Angular uses data

How to make AJAX calls

Xelom
  • 1,615
  • 1
  • 13
  • 23
0

Although this is not the usual way to do things in Angular, you can achieve what you want, adding a watch to your data

$scope.$watch(
    function () { return  $("#mydata").data("a");}, 
    function(newValue) {
        $scope.mydata = newValue;
    }, true);

Basically we are adding a change listener to your data.

Please check this plunker, where the jquery data is changed every 2 seconds, and the div reacts to this change.

bfcamara
  • 323
  • 1
  • 2
  • 10
  • that doesn't work if you set the change manually via the console – raphael_turtle Apr 18 '13 at 14:45
  • @raphael_turtle You are right. Outside of Angular we have to use $apply. So, to work on console we have to do this: angular.element("body").scope().$apply(function() { $("#mydata").data("a")[0].name="bill"; }); – bfcamara Apr 18 '13 at 15:33