javascript - Binding data with angular. (Calling method into a view) -


i want bind data angular, made example , works i'm having problems integrate stuff app.

this controller of app

angular.module('app', ['dcafe.navigation','ui.bootstrap'])  .controller('headlinereportcontroller', function($scope, $http, $interpolate, $filter, datafactory, d3factory, $timeout){      //code      $scope.senddata = function(){          $http.post('http://localhost:8080/xxx/xxx/', data, config)          .success(function (data, status, headers, config) {             $scope.postdataresponse = data;             console.log("success");             console.log("status code: " + status);          })         .error(function (data, status, header, config) {             //$scope.responsedetails = "data: " + data +                 console.log("error");                 console.log("status: " + status);                 console.log("headers: " + header);         });      };     $scope.senddata();      //more code  }); 

i working senddata() function inside controller, in view used ng-controller , ng-repeat, things different in second app.

they call controller @ begining of view this:

<span ng-controller="headlinereportcontroller vm"> 

so tried ng-repeat in workig app, this:

<tr ng-repeat="data in postdataresponse.result"> </tr> 

but can see in controller above $scope.senddata = function() {}

is part of headlinereportcontroller in case dont know how ng-repeat, thinking in this:

ng-repeat="data in senddata()" 

but it's not working.

if using controller syntax change $scope 'this'

var self = this; self.senddata = function(){      $http.post('http://localhost:8080/xxx/xxx/', data, config)      .success(function (data, status, headers, config) {         self.postdataresponse = data;         console.log("success");         console.log("status code: " + status);      })     .error(function (data, status, header, config) {         //$scope.responsedetails = "data: " + data +             console.log("error");             console.log("status: " + status);             console.log("headers: " + header);     });  }; self.senddata(); 

and use view model declared on controller as

<tr ng-repeat="data in vm.postdataresponse.result"> </tr> 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -