使用angularJS

时间:2017-04-17 09:42:41

标签: angularjs

我有按钮提交的复选框列表,当我点击提交时,我必须在其他视图表中获取所有选中的值。我找到了很多答案,但是他们都建议在同一个视图中获取值,但我需要在其他视图中获取值(ajoutFactAdmin2),我该怎么做呢。这是代码:

ajoutFactAdmin2.html

<div class="row" ng-repeat="x in namesF3">

          <div class="col"><input type="checkbox" name="" ng-modal="x.selected" ng-checked="exist(x)" ng-click="toggleSelection(x)" ng-true-value="'{{x.CodeEnvoiColis}}'" ng-false-value="''" id="'{{x.CodeEnvoiColis}}'"></div>
          <div class="col" >{{x.CodeEnvoiColis}}</div>   
          <div class="col" width="20%">{{x.StatutColis}}  </div>
          <div class="col" width="20%">{{x.VilleDestColis}}</div> 

</div>

<div class="selectedcontent">
            <h3> Selected Names </h3>
            <p ng-repeat = "selectedName in selected"> {{selectedName.CodeEnvoiColis}} </p>
</div>
          <a class="button button-info"   ng-click="toggleSelection(x)"  href="#/ajoutFactAdmin2" style="background-color:#1627C0;float: right;">Ajouter</a> 

app.js:

$scope.selected = [];
           $scope.namesF3 = [];
          $scope.exist = function(item){
            return $scope.selected.indexOf(item) > -1;
          }

          $scope.toggleSelection = function(item){
             var x = [];
            var idx = $scope.selected.indexOf(item);
            if(idx > -1){
                 $scope.selected.splice(idx, 1);
            }
             else{
                 $scope.selected.push(item);
             }

          }

1 个答案:

答案 0 :(得分:0)

实现此目的主要有3种方法

  1. 本地存储/会话存储:
  2. angular.module('app').factory('tempStorageService',function(){
      var data={};
      return{
        setData:function(tempData){
          data=tempData;
        },
        getData:function(){
          return data;
        }
      }
    })
    
    1. 厂/服务
    2. $rootScope.tempData = YourData;
      1. $ rootScope
      2.   

        x <- data.table(ID=1:3,A=letters[3:1]) y <- data.table(ID=1:3,B=letters[1:3])

        我更喜欢使用localstorage选项,因为如果刷新浏览器,使用factory或$ rootscope存储的数据就会消失。