Javascript AngularJS:当route收到一个数字时如何隐藏菜单
当路线将收到号码时,如何隐藏Javascript AngularJS:当route收到一个数字时如何隐藏菜单,javascript,angularjs,Javascript,Angularjs,当路线将收到号码时,如何隐藏菜单元素 例如: 第一种情况:如果当前路由为http:base.com/files,则当路由更改为http:base.com/files/1(可能有任何数值)时,菜单应隐藏 第二种情况:如果当前路由为http:base.com,则当路由更改为http:base.com/diff/1/2(可能有任何数值)时,菜单应隐藏 第三种情况(与第二种情况类似,只是默认路由不同):如果当前路由为http:base.com/diff,则当路由更改为http:base.com/diff
菜单
元素
例如:
第一种情况:如果当前路由为http:base.com/files,则当路由更改为http:base.com/files/1(可能有任何数值)时,菜单应隐藏
第二种情况:如果当前路由为http:base.com,则当路由更改为http:base.com/diff/1/2(可能有任何数值)时,菜单应隐藏
第三种情况(与第二种情况类似,只是默认路由不同):如果当前路由为http:base.com/diff,则当路由更改为http:base.com/diff/1/2时,菜单应隐藏(可能有任何数值)
基本上,当用户从类文件中选择一个复选框时(它将只得到一个数字),或者当用户从类差异中选择两个复选框时(它将得到两个数字/x/y),路由会发生变化
检查这个答案
var-app=angular.module('myApp',[])
app.controller('DemoController',函数($scope){
$scope.collapsed=false;
$scope.selectedObject={
“num”:0,
“项目”:”
};
$scope.checkValue=函数(编号、项目){
$scope.selectedObject.num=parseInt(数字);
$scope.selectedObject.item=项目;
}
$scope.toggleMenu=函数(){
$scope.collapsed=true;
}
})
第一
第二
第一
第二
您正在使用哪个路由库?使用ng if=“YOUR_FLAG==true”隐藏菜单元素。并在复选框上使用ng change。您所说的“路由库”是什么意思?对不起,我刚开始用angularjs实现一些东西,我没有这方面的经验。我没有得到你想要的。但是更新了你的小提琴如何隐藏菜单元素。根据您的要求更改此选项。如果(scope.number\u of_files==1)
,是否有方法为内的菜单添加触发器单击事件?该语句检查路由何时更改如果评估了该条件,我想在
上添加一个单击触发器这是部分解决方案,您必须从diff
中选择两个复选框以隐藏该菜单。。。
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app>
<a href="#" class="toggle-menu" ng-click="collapsed=!collapsed">Click to toggle menu</a>
<div class="menu" ng-show="collapsed">
<div class="files">
<input type="checkbox" />
<label>first</label>
<input type="checkbox" />
<label>second</label>
</div>
<div class="diff">
<input type="checkbox" />
<label>first</label>
<input type="checkbox" />
<label>second</label>
</div>
</div>
</div>
scope.update_selection = function(updated_file_id){
selected_count = 0;
if (scope.is_initial_selection){
scope.is_initial_selection = false;
scope.file_map = {};
scope.file_map[updated_file_id] = true;
}
if (scope.number_of_files == 1){
path = '/files/' + updated_file_id;
$location.path(path);
}
else {
updated_file_selected = scope.file_map[updated_file_id];
if (updated_file_selected) {
//search for the other file
found = false;
for (file_id in scope.file_map){
if (file_id == updated_file_id)
continue;
found = scope.file_map[file_id];
if (found == true){
scope.file_1_id = file_id;
scope.file_2_id = updated_file_id;
break;
}
}
if (!found){
scope.file_1_id = updated_file_id;
return;
}
}
path = '/diff/' + scope.file_1_id + '/' + scope.file_2_id
$location.path(path);
}
}