0

When i click the button i want to send the val of label number to the func getUserDetails in controller and loop the data that returnd in result on the directive and popup to the screen the directive

<div ng-controller="IndexController">
<label id="number" >5</label>
<input type="button" ng-click="getUserDetails()" >
</div>


app.controller('IndexController', ['$scope', function ($scope) {   
    $scope.getUserDetails = function() {
        var result = $http.get("/getUserDetails?id=" + number)

    }   
}]);


directive 
<div ng-repeat m in result>
     <label>{{m.a}}</label>
      <label>{{m.b}}</label>
</div>
miley
  • 21
  • 2
  • What's the problem? That's not how a ng-repeat should look either. – Mathemats Dec 21 '15 at 00:05
  • the problem is that i dnot know the syntax – miley Dec 21 '15 at 00:13
  • This feels like an [XY problem](http://meta.stackexchange.com/a/66378/297619). Your code has a few structural errors, and you seem to be referring to the ` – Claies Dec 21 '15 at 01:22

1 Answers1

0

Is this what you are trying to do?

HTML

<div ng-controller="IndexController">
  <div ng-repeat="user in userList">
     <label id="{{user.number}}">{{user.number}}</label>
     <input type="button" ng-click="getUserDetails({{user.number}})">   
  </div>
</div>

JS

app.controller('IndexController', ['$scope', function ($scope) {   
    $scope.getUserDetails = function(number) {
        var httpPromise = $http.get("/getUserDetails?id=" + number);
        httpPromise.then (function (result) {
            $scope.detailsList = result.data.detailsList;
        }).catch ( function (error) {
            //log error
        }); 
    }   
}]);
georgeawg
  • 48,608
  • 13
  • 72
  • 95