简体   繁体   English

如何将变量从角度控制器传递给jquery

[英]How to pass variables from angular controller to jquery

I have two html divs, each having a bunch of input fields. 我有两个html div,每个都有一堆输入字段。 I also have an angular controller that gets the data entered in the input fields and checks if they are valid (ie: email, passwords match, etc). 我还有一个角度控制器,它可以获取输入字段中输入的数据,并检查它们是否有效(即:电子邮件,密码匹配等)。 What I'm trying to do is hide the first div and show the second one once the controller says that the text entered in the first div is valid. 我想要做的是隐藏第一个div并在控制器说第一个div中输入的文本有效时显示第二个div。 Here is what the html looks like: 这是html的样子:

  <div id = "stageOne">
  <!-- whole bunch of inputs here -->
 </div>

<a class = "btn" id = "stageOneDone" ng-click = "checkFields(true)">Continue</a>
  <!-- First stage ends here-->


  <div align = "center" id = "stageTwo" style = "display: none">
     <!-- whole bunch of inputs here -->
  </div>

  <script>

  $(function(){

      $('#stageOneDone').click(function(){

        //var completedIncorrectly = something

        if(!completedIncorrectly){
          $('#stageOne').hide();
          $('#stageTwo').show();
        }

      })


  });

  </script>

The function checkFields() expects the value true when it should check the values of the first div and false for the second div. 函数checkFields()在检查第一个div的值时要求值为true,为第二个div检查false。 What I can't figure out how to do is get the return value of the function and use it in jquery. 我无法弄清楚该怎么做是获取函数的返回值并在jquery中使用它。

EDIT: If you're thinking why not just show/hide the divs using angular, I want to use jquery's animations. 编辑:如果您正在考虑为什么不使用angular显示/隐藏div,我想使用jquery的动画。

通过在控制器中编写所有jquery来解决这个问题。

You can set variable inside controller, like $scope.step = 'one'; 您可以在控制器内部设置变量,例如$ scope.step ='one';

<div ng-show="step='one'">first step</div>
<div ng-show="step='second'">second step</div>
...

You don't need jQuery to do this. 你不需要jQuery来做到这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM