How i send value when i click button to server and popup directive

感情迁移 提交于 2020-01-07 03:04:03

问题


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>

回答1:


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
        }); 
    }   
}]);


来源:https://stackoverflow.com/questions/34387333/how-i-send-value-when-i-click-button-to-server-and-popup-directive

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!