javascript - Angularjs data binding with a data attribute object -


i have json attached data attribute on page. json data used build table in angularjs. i'm using coffeescript , haml.

    app = angular.module("myapp", [])      app.controller "tablectrl", ($scope) ->       $scope.table =  $("#mydata").data("myjson")       #table{"ng-app"=>"myapp","ng-controller" =>"tablectrl"}       %table         %tbody           %tr{"ng-repeat"=>"(i,item) in table" }}"}             %td {{item.name}} 

the page loads data table. elsewhere on page json on data attribute can changed user jquery. how can have 2-way binding between json data , table? i.e want table change json on data attribute changed locally.

what need tell angularjs observe $("#mydata").data("myjson") changes , update $scope.table when change occurs. try adding following code controller (sorry don't know coffeescript).

$scope.$watch(     function () { return $("#mydata").data("myjson");},      function(newjson) {         $scope.table = newjson;     },     true ); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -