问题描述
我有带有按钮Submit的复选框列表,当我单击Submit时,我必须在其他视图表中获取所有选中的值.我找到了很多答案,但是它们都建议在同一视图中获取值,但是我需要在其他视图中获取值(ajoutFactAdmin2),我该怎么做.这是代码:
I have list of checkbox with button submit , and I when i click on submit, I have to get all checked values in other view table. I find a lot of answers, but they all propose to get values in the same view,but I need to get values in other view(ajoutFactAdmin2), how can I do that please. this is the code:
ajoutFactAdmin2.html
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);
}
}
推荐答案
主要有3种方法可以实现
There are mainly 3 ways to achieve this
- 本地存储/会话存储:
To set value in local storage:
localStorage.setItem("key","value");
To get value:
localStorage.getItem("key");
- 工厂/服务
angular.module('app').factory('tempStorageService',function(){
var data={};
return{
setData:function(tempData){
data=tempData;
},
getData:function(){
return data;
}
}
})
- $ rootScope
我宁愿使用localstorage选项,因为如果刷新浏览器,使用工厂或$ rootscope存储的数据将消失.
I would prefer to go with localstorage option because if you refresh the browser the data that is stored using factory or with $rootscope vanishes.
这篇关于使用angularJS在另一个视图中获取检查值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!