使用angularjs将id从表发送到控制器



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

app.js:

。控制器("etudmodifCtrl", ["$scope", "$http", "filterFilter", "$rootScope", "logger", "$filter", "$modal", "$log", function ($scope, $http, filterFilter, $rootScope, logger, $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>

我尝试通过打开函数发送id,但我得到一个语法错误感谢您的帮助

在按钮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) {
   ............
   ............
 }

要了解更多细节,谁将值从控制器传递到模型控制器,请参阅传递参数到modal

相关内容

  • 没有找到相关文章

最新更新