简体   繁体   English

刷新页面后ng-click停止工作

[英]ng-click stops working after page refreshes

I have already built a big part of my app the same way I am building this page. 我已经按照构建此页面的相同方式构建了应用程序的很大一部分。 It's a login page that checks if the user exists on the database. 这是一个登录页面,用于检查用户是否存在于数据库中。

The problem is that the ng-click directive is driving me crazy! 问题在于ng-click指令使我发疯! It works only when it wants, I hit refresh: it works! 它仅在需要时才起作用,我按下了刷新: 它起作用了! I hit refresh again: it stops working. 我再次点击刷新: 它停止工作。 I hit refresh one more time: it works! 我又点击刷新一次: 它有效!

I copied and pasted the example from the ngClick documentation page and the same thing happens. 我从ngClick文档页面复制并粘贴了示例,并且发生了同样的事情。 So, the problem is not with my controller. 因此,问题出在我的控制器上。

Code: 码:

<button ng-click="count = count + 1" ng-init="count=0">
  Increment
</button>
<span>
  count: {{count}}
</span>

Controller: 控制器:

'use strict';

angular.module('app').controller('loginCtrl', function ($scope, Data) {
  $scope.terapeuta = {};

  $scope.logar = function (terapeuta) {
      console.log('test');
  }

});

I suspect that it maybe caused by something not loading properly. 我怀疑这可能是由于某些无法正确加载的原因引起的。 But everything other than ngClick works perfectly. 但是除ngClick之外的所有其他功能都可以正常运行。

I solved the problem by removing the ngTouch module. 我通过删除ngTouch模块解决了该问题。

It was causing some sort of conflict, it is now working as it should. 它正在引起某种冲突,现在正在按应有的方式工作。

尝试将递增count变量封装在控制器的单独函数中,然后用ng-click调用它,看看是否可行。

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

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