0

I wonder how can I send the id of the selected row from my table to the controller when I try to show the details of these row,this is my code:

app.js:

.controller("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)
    })
}

}])

my html code:

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

I try to send the id via the open function but I get a syntax error thanks for help

hanali
  • 227
  • 7
  • 17
  • 2
    please scale your html down to the minimal needed to represent the problem. It's very hard to read through all your various classes and inline styles especially with such poorly formatted code – charlietfl Oct 13 '15 at 15:02
  • thanks charlietfl for your comment,my problem is that I can't send the id of selected row (with {{store.Id}}) to the controller "etudmodifCtrl" in which I get the details of selected student – hanali Oct 13 '15 at 15:08
  • 1
    make the code simple and readable if you want help – charlietfl Oct 13 '15 at 15:09
  • I have edited my code,is it clear? – hanali Oct 13 '15 at 15:17

1 Answers1

2

In button bg-click pass the id by using ng-click="open(store.storeId)" complete code

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

And change your open function to accept a parameter like this

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

for more detail, who to pass value from controller to model controller see this Pass parameter to modal

Community
  • 1
  • 1
Ali Adravi
  • 21,707
  • 9
  • 87
  • 85