如何将ng-model传递给Web服务的函数?

时间:2018-01-30 18:20:00

标签: angularjs

使用AngularJS,我想发出依赖于传入的ng模型的Web请求。我不确定如何正确传递它。 ng模型应该是函数sortval

这是我的HTML:

<div ng-app="myApp">
  <div ng-controller="MainCtrl">
    <table>
      <tr>
        <th></th>
        <th ng-model="User" ng-click="getAdminList()">User</th>
        <th ng-model="First Name" ng-click="getAdminList()">First Name</th>
        <th ng-model="Last Name" ng-click="getAdminList()">Last Name</th>
        <th ng-model="Job Title" ng-click="getAdminList()">Job Title</th>
        <th ng-model="EmpID" ng-click="getAdminList()">Emp ID</th>
        <th ng-model="OfficerCode" ng-click="getAdminList()">Officer Code</th>
        <th ng-model="Email" ng-click="getAdminList()">Email</th>
        <th ng-model="Telephone" ng-click="getAdminList()">Telephone</th>
        <th ng-model="Fax"ng-click="getAdminList()">Fax Number</th>
        <th ng-model="Location" ng-click="getAdminList()">Location Description</th>
        <th ng-model="Mailstop" ng-click="getAdminList()">Mailstop / Banking Center #</th>
      </tr>
    </table>
  </div>
</div>

这是我的功能:

    $scope.getAdminList = function(sortval) {
    adminList = $http({
      method: 'GET',
      url: this.prepContext(siteOrigin+"/corporate/projecthub/anchormn/associates","User Administration","?$orderBy=" + sortval + "&$top=1000&$filter=UserStatus eq 'Active'"),
      headers: {
        "Accept": "application/json; odata=verbose"
      }
    }).then(function(data) {
      //$("#articleSection").fadeIn(2000);
      console.log("adminlist", data.data.d.results);
      $scope.users = data.data.d.results;
    });
  };

2 个答案:

答案 0 :(得分:0)

ng-click属性中,只需传递字符串。

<th ng-click="getAdminList('User')">User</th>

答案 1 :(得分:0)

应该在表单元素上使用

ng-model,但是如果需要将值传递给ng-click函数,则可以将其作为字符串传递

 <th ng-model="Last Name" ng-click="getAdminList('Last Name')">Last Name</th>