angularjs - How to update data on server via AJAX when ng-model input value is changed -
I'm new to kangaroo and I have a problem, I can not find a solution. Any help is appreciated.
I'm bringing all the data from one server to one controller using $ http.get ("/ admin / getGraphData") . When user
& lt; Input & gt; Edit the element, the data is updated by the corner in the controller, when this happens, I want to update the data (MySQL) on the server immediately. Is this an easy way to gain? If I can do something like this:
$ scope.onDayValueChange (month, year, day, newcomer) {$ http.post ("/ admin / updateDayValue", {...}) } How to stop controllers data and how exactly is the exact indicator of the object being changed or something like this? Thanks a lot!
The data model is quite simple month (January, February, March ...) which contains some values for each day in a day:
{month: 1 , Year: 2013, data: [day: 1, val: 11}, {day: 2, val: 14}, ..., {day: 31, val: 80}]} {month: 2, year: 2013 , Data: [{day: 1, vall: 22}, {day: 2, val: 124}, ..., {day: 30, val: 2}}} ... Looks like something in HTML:
< / P>
Code:
& lt; Div ng-app = "graph" ng-controller = "graphctrl" & gt; & Lt; Ul & gt; & Lt; Li class = "monthtime" ng-repeat = "month in months" & gt; & Lt; Period & gt; {{Month Name [Month Month -1]} ({{Month Month}}}. {{Month Month}}}. & Lt; / span & gt; & lt; ul category = "Monthday" & Gt; & lt; li ng-repeat = "dayItemItem.data" & gt; Labels & gt; {{dayItem.day}}. & Lt; input type = "number" ng-model = "day item .val "value =" {{dayItem.val}} "Minimum =" 0 "Required & gt; & lt; / Labels & gt; & lt; / li & gt; & lt; / ul & gt; & lt; / Li> << div> 5 / angular.min.js "& gt; & lt; / script & gt; script & gt; var app = angular module ('graph'); app.controller ('GraphCtrl', function ($ hem) , $ Http) {getData (); // Load all the data in the model function getData () {$ http.get ("/ admin / getGraphData"). Success (function (data) {$ scope.months = data ;}}} $ Scope.monthNames = ['Jan', 'Fur', 'Mar', 'Apr', 'May', 'Jun', 'Julie', 'August', 'September', 'Akt' 'Nov', 'Dec'];}); / script>
NZLUR is a good option. Your post (Pot is probably more suitable) if you leave the input field
Comments
Post a Comment