javascript - binding data in angularJS -
so have simple controller in app.js
var app = angular.module('graphplotterdemoapp', []); app.controller('plotctrl1', function ($scope) { $scope.data = [{ x: [1, 2, 3, 4], y: [10, 15, 12, 17]}]; }); and trying bind table ...
<!doctype html> <html> <head lang="en"> <script src="angular.min.js"></script> <script src="app.js"></script> </head> <body ng-app="graphplotterdemoapp"> before div = plotctrl1 <div ng-controller="plotctrl1"> {{data}} <table> <thead><tr><td>x</td><td>y</td></tr></thead> <tbody ng-repeat='x1 in data[0].x'> <tr> <td><input type='number' ng-model='x1'></td> <td><input type='number' ng-model='data[0].y[$index]'></td> </tr> </tbody> </table> </div> </body> </html> it turns out there two-way data binding ng-model='data[0].y[$index] not ng-model='x1' !
anyone knows reason this??
check out page in wiki. https://github.com/angular/angular.js/wiki/understanding-scopes#ng-repeat
it's understanding difference between objects , primitives when using angular scoping.
Comments
Post a Comment