angularjs - Angular javascript array is empty? -


angular javascript array empty? have array of checkboxes databound angular scoped list need check few checkboxes , send bind them second angular scoped array:

my html:

<tr ng-repeat="item in pageditems[currentpage]"      ng-controller="dealercommaintainctrl">   <td align="center">      <input type="checkbox" id="{{item.idarticle}}"             ng-value="item.idarticle"             ng-checked="selected.indexof(item.idarticle) > -1"             ng-click="toggleselect(item.idarticle)" />    </td>   <td>     <a href="/dealercoms/articledownload?filename={{item.filename}}&idarticle={{item.idarticle}}"         class="btn btn-xs btn-total-red btn-label"><i class="ti ti-download"></i></a>   </td>   <td>{{item.datearticle | date:'dd/mm/yyyy'}}</td>   <td>{{item.title}}</td>   <td>{{item.archive}}</td> </tr> 

and js in controller:

$scope.selected = [];  $scope.toggleselect = function toggleselect(code) {   var index = $scope.selected.indexof(code)    if (index == -1) {     $scope.selected.push(code)   } else {     $scope.selected.splice(index, 1)   } }  $scope.archivedocs = function() {   var selectedoptionz = $scope.selection;   console.log(selectedoptionz); }; 

i tried code , fixed problem, adding controller on element above ng-repeat. alert check, in selected-array. code, works fine on system:

<html> <head> </head> <body ng-app="app"> <table ng-controller="dealercommaintainctrl">     <tbody>         <tr ng-repeat="item in pageditems" >             <td align="center">                   <input type="checkbox" id="{{item.idarticle}}" ng-value="item.idarticle" ng-checked="selected.indexof(item.idarticle) > -1" ng-click="toggleselect(item.idarticle)" />               </td>             <td><a href="/dealercoms/articledownload?filename={{item.filename}}&idarticle={{item.idarticle}}" class="btn btn-xs btn-total-red btn-label"><i class="ti ti-download"></i></a></td>             <td>{{item.datearticle | date:'dd/mm/yyyy'}}</td>             <td>{{item.title}}</td>             <td>{{item.archive}}</td>          </tr>      </tbody>     </table>       <!-- jquery -->     <script src="./jquery-2.1.4/jquery.min.js"></script>     <!-- angularjs -->     <script src="./angular-1.4.5/angular.min.js"></script>     <script>         var app = angular.module("app", []);          app.controller("dealercommaintainctrl", function($scope){             $scope.pageditems = [                 {idarticle: 1, title: "test1", archive: "archiv1"},                 {idarticle: 2, title: "test2", archive: "archiv1"},                 {idarticle: 3, title: "test3", archive: "archiv1"},                 {idarticle: 4, title: "test4", archive: "archiv1"}             ];             $scope.selected = [];          $scope.toggleselect = function toggleselect(code) {             var index = $scope.selected.indexof(code)              if (index == -1) {                 $scope.selected.push(code)             }             else {                 $scope.selected.splice(index, 1)             }             alert(json.stringify($scope.selected));         }         });      </script> </body> </html> 

just try it, hope solve problem...


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -