AngularJS显示和隐藏

AngularJS显示和隐藏,angularjs,Angularjs,大家好,我想在angularjs(bootstrap3.3)中的模式弹出窗口上显示和隐藏div以下是我编写的代码,在页面加载时显示所需的myModal_用户名1,但在控制器函数调用时单击submit,myModal_用户名1应为明显错误,其他div应为明显正确。。但同样的事情并不幸福 控制器代码: angular.module('ratefastApp') .controller('LoginCtrl', function ($scope, Auth, $location) { $scop

大家好,我想在angularjs(bootstrap3.3)中的模式弹出窗口上显示和隐藏div以下是我编写的代码,在页面加载时显示所需的myModal_用户名1,但在控制器函数调用时单击submit,myModal_用户名1应为明显错误,其他div应为明显正确。。但同样的事情并不幸福

控制器代码:

angular.module('ratefastApp')
  .controller('LoginCtrl', function ($scope, Auth, $location) {
 $scope.showUser = 'true';
 $scope.x= function(form) {
 $scope.showPass = 'false';
}}
视图:

<div class="modal fade" id="myModal_username" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Forgot your Username ?</h4>
      </div>
      <!-- div check -->

  <div ng-show="showUser" id="myModal_username1" class="modal-body"
 ng-include src="'views/partials/forgotstage_username.html'">      
       </div>
      <!-- div question -->

  <div ng-hide="showUser" id="myModal_username2" class="modal-body"
 ng-include src="'views/partials/forgot_username.html'">       
       </div>

    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

&时代;
忘记你的用户名了吗?
函数
x()
不会更改视图使用的
showUser
的值。它初始化名为
showPass
的新范围字段:

 $scope.showPass = 'false';
另外,ng include有自己的作用域,继承自控制器作用域。因此,在此子作用域中设置字段会将该字段添加到子作用域中,但不会更改控制器作用域中字段的值

你也不应该用字符串来表示布尔值。使用
true
false
,而不是
'true'
'false'

因此,代码应该是:

$scope.visibility = {
    showUser: true
}

$scope.submit = function(form) {
    $scope.visibility.showUser = false;
}