Friday 15 March 2013

AngularJS http post loop -



AngularJS http post loop -

how can phone call function once. when so, calling loops. html: calling function controller. find value of index.

<body ng-controller="mainctrl"> <div ng-repeat="id in arr"> {{sendpost(id)}} </div> <br> {{namestr}} </body>

js: function request server value

app.controller('mainctrl', function($scope, $http) { $scope.arr=[]; $scope.arr.push(1); $scope.arr.push(2); $scope.arr.push(3); $scope.namestr=""; $scope.newname = ""; $scope.sendpost = function(names) { $scope.namestr=$scope.namestr+' '+names; var info = $.param({ json: json.stringify({ name: names }) }); $http.post("/echo/json/", data).success(function(data, status) { //select database if (data==1){ homecoming '1111' } else { homecoming '2222' } }) } });

http://plnkr.co/edit/zhao5jueeug1kgxnhls0?p=preview

this bad thought in general

{{sendpost('Василий')}}

sendpost method , http.post called every single $digest process, , $digest triggered model alter this

$scope.hello = data;

will cause $digest , http request, explain more want accomplish , i'll extend plunker

angularjs angularjs-scope angularjs-http

No comments:

Post a Comment