angularjs - AngularJS 中的范围变量数据没有改变

标签 angularjs angularjs-ng-click

我想通过下面的代码更改范围可用数据,但它不起作用。我没有收到任何错误,但它没有按预期工作。

$scope.secondcity1 = false;
$scope.hidecity1 = function() {
  alert(secondcity1);
  $scope.secondcity1 = false;
  $scope.city1 = ''; 
  alert(secondcity1);
}

我正在使用警报(secondcity1);这是为了显示警报框,但它没有显示任何内容,

<div ng-style="{'display':secondcity1 == false?'none':'block'">  
  <!-- some codes -->
  <button type="button" class="remove" ng-click="hidecity1()">-</button>
</div>

上面的代码也不起作用。我希望隐藏 div,但它没有隐藏它。

最佳答案

试试这个,在 AngularJs 中要访问对象,你必须使用 $scope 就像 $scope.object

$scope.secondcity1 = false;
$scope.hidecity1 = function() {
        alert($scope.secondcity1);
        $scope.secondcity1 = false;
        $scope.city1 = ''; 
        alert($scope.secondcity1);
    }

关于angularjs - AngularJS 中的范围变量数据没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43648359/

相关文章:

angularjs - 在 AngularJs 中装饰 ng-click 指令

javascript - AngularJS - 通过 ng click 在 ng Repeat 中的项目之间切换

javascript - 我有来自 2 个数据库的请求数据。如何将代码合并到一个函数中?

javascript - 我可以从具有隔离作用域属性的元素的内部 HTML 访问父作用域吗?

javascript - Angular Breeze 设置

javascript - 喜欢/不喜欢 AngularJs 中的功能

angularjs - 我想使用node.js将数据写入mongodb数据库

angularjs - AngularJS 中的绑定(bind)和消化是如何工作的?

angularjs - Ctrl 单击 ng-click 在新选项卡中打开页面