0

我想知道当我尝试显示这些行的详细信息时,如何将所选行的 id 从我的表发送到控制器,这是我的代码:

应用程序.js:

.controller("etudmodifCtrl", ["$scope", "$http", "filterFilter", "$rootScope", "logger", "$filter", "$modal", "$log", function ($scope , $http, filterFilter, $rootScope, 记录器, $filter, $modal, $log) {

$http({
    method: 'GET',
    url: 'http://localhost:50001/api/Students/' + $scope.store.id
}).success(function (data) {
    $scope.firstname = data.FirstName;
    $scope.lastname = data.LastName;
    $scope.email = data.Email;
    console.log("success");
}).error(function (data, status, headers, config) {
    console.log("data error ...");
});

$scope.open = function () {
    var modalInstance;
    modalInstance = $modal.open({
        templateUrl: "myModalContent1.html",
        controller: "ModalInstanceCtrl",
        resolve: {
            items: function () {
                return $scope.items
            }
        }
    }), modalInstance.result.then(function (selectedItem) {
        $scope.selected = selectedItem
    }, function () {
        $log.info("Modal dismissed at: " + new Date)
    })
}

}])

我的html代码:

    <table class="table table-responsive table-hover" ng-controller="etudmodifCtrl">
        <tr ng-repeat="store in currentPageStores">
            <td align="center">{{store.LastName}}</td>
            <td align="center">{{store.FirstName}}</td>
            <td align="center">{{store.Email}}</td>
            <td align="center">{{store.Class}}</td>
            <td align="center">
            <script type="text/ng-template" id="myModalContent.html">
            < div class ="modal-header">Modify Informations</div><div class = "modal-body modal-dialog modal-lg3" data-ng-controller = "etudmodifCtrl">

  <div class="panel-body" >
       <div class="col-md-6">
           <div class="form-group">
             <label for="" class="col-sm-2">FirstName</label>< div class = "col-sm-10"><input type = "email" class ="form-control" ng-model = "firstname"> 
</div>
            </div >< /div>
            <div class="form-group">
             <label for="" class="col-sm-2">LastName</label>< div class = "col-sm-10"><input type = "email" class ="form-control" ng-model = "lastname"> 
</div>
            </div >< /div>
                     <div class="form-group">
             <label for="" class="col-sm-2">Email</label>< div class = "col-sm-10"><input type = "email" class ="form-control" ng-model = "email"> 
</div>
            </div >< /div>                                
                </script>
            </td>
        </tr>
    </table>
    <button type="button" onclick="window.location = '" aria-label="Center Align" ng-click="open()" data-toggle="modal" data-target=".bs-example-modal-lg">Modify</button>

我尝试通过 open 函数发送 id,但出现语法错误,感谢您的帮助

4

1 回答 1

2

在按钮 bg-click 中使用ng-click="open(store.storeId)"完整代码传递 id

<button type="button" 
  aria-label="Center Align" 
  ng-click="open(store.storeId)" 
  data-toggle="modal" 
  data-target=".bs-example-modal-lg">Modify</button>

并更改您的 open 函数以接受这样的参数

 $scope.open = function (id) {
   ............
   ............
 }

有关更多详细信息,谁将值从控制器传递到模型控制器,请参阅此传递参数到模态

于 2015-10-13T15:20:39.263 回答