ng-hide / ng-show 无法通过 ng-click 调用的函数工作
ng-hide / ng-show not working from function called with ng-click
我有两个屏幕要显示在一个区域中,我正在使用 ng-hide / ng-show 进行相同的操作!!
我的代码是:
控制器内部
$scope.grid1show = 'true' // intially this grid will shown on page load
$scope.grid2show = 'false' // Intially this grid is hide on page load
// Function
$scope.showGrid = function(){
$scope.grid1show = 'false';
$scope.grid2show = 'true';
console.log ("==after==" +$scope.grid1show );
console.log ("===after==="+ $scope.grid2show );
};
在我的 HTML
<div ng-show="grid1show"> Shown this div initially
<span ng-click="showGrid2()">Click for grid2</span> // IT should fire function which should show grid2 and hide grid1
</div>
<div ng-show="grid2show"> Hide this div intially </div>
但是虽然在控制台中,它正在发生变化,但实际上并没有隐藏和显示特定的 div!!
这里有什么我遗漏的吗?
为什么要将值存储为字符串?
$scope.grid1show = 'false';
$scope.grid2show = 'true';
它们不应该是布尔值吗?
$scope.grid1show = false;
$scope.grid2show = true;
我有两个屏幕要显示在一个区域中,我正在使用 ng-hide / ng-show 进行相同的操作!!
我的代码是:
控制器内部
$scope.grid1show = 'true' // intially this grid will shown on page load
$scope.grid2show = 'false' // Intially this grid is hide on page load
// Function
$scope.showGrid = function(){
$scope.grid1show = 'false';
$scope.grid2show = 'true';
console.log ("==after==" +$scope.grid1show );
console.log ("===after==="+ $scope.grid2show );
};
在我的 HTML
<div ng-show="grid1show"> Shown this div initially
<span ng-click="showGrid2()">Click for grid2</span> // IT should fire function which should show grid2 and hide grid1
</div>
<div ng-show="grid2show"> Hide this div intially </div>
但是虽然在控制台中,它正在发生变化,但实际上并没有隐藏和显示特定的 div!!
这里有什么我遗漏的吗?
为什么要将值存储为字符串?
$scope.grid1show = 'false';
$scope.grid2show = 'true';
它们不应该是布尔值吗?
$scope.grid1show = false;
$scope.grid2show = true;