问题
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