【发布时间】:2026-01-08 08:20:05
【问题描述】:
我正在使用带有“Angular Material”实现的 angularjs(这里:https://material.angularjs.org/latest/#/)
我正在使用 SideNav 组件:https://material.angularjs.org/latest/#/demo/material.components.sidenav 在单击菜单链接时打开横向容器。它现在正在工作......但是当我单击菜单项时,我应该将布尔变量的值从 false 更改为 true.. 这不会发生。我不知道具体为什么。在我的控制器中,我有这部分代码:
$scope.toggleRight = buildToggler('right');
$scope.myBoolean = false;
/**
* Build handler to open/close a SideNav; when animation finishes
* report completion in console
*/
function buildToggler(navID) {
var debounceFn = $mdUtil.debounce(function(){
$mdSidenav(navID)
.toggle()
.then(function () {
$log.debug("toggle " + navID + " is done");
});
},300);
return debounceFn;
};
$scope.close = function () {
$mdSidenav('right').close()
.then(function () {
$log.debug("close RIGHT is done");
});
};
这是打开和关闭容器的部分。然后在我的html中
<li>
<a data-ng-click="myBoolean = true;">
Open the container
</a>
</li>
因此,如果变量为“false”,那么当单击菜单项时,现在应该为“true”。但仍然是假的..怎么了?
【问题讨论】:
-
您如何检查该变量是否仍然为假?我在您的代码中的其他任何地方都看不到 classContent。
-
对不起,现在更正了。
-
我仍然看不到使用 myBoolean 的代码。您在控制器中将其设置为 false,然后从视图中将其设置为 true。您如何检查它是否不真实?
标签: javascript html angularjs