角ng-click不触发 [英] Angular ng-click not firing

查看:60
本文介绍了角ng-click不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了许多不同的方法来尝试使它生效.我读过:

I have tried many different things to try to get this to work. I have read:

ng-click在onclick不会在AngularJS中触发

AngularJS:ng-click无效

还有很多

HTML:

<div ng-controller="testApp">
  <div id="bla">
    <button ng-click="obey('bla')">Close</button>
    <h4>Bla bla bla</h4>
  </div>
</div>

JS:

var testApp = angular.module('testApp', []);
testApp.controller('testController', function($scope) {
  $scope.obey = function test(id) {
    $("#" + id).fadeOut("slow", function() {
      this.remove()
    });
  };
});

由于某种原因,div根本不会消失.

For some reason the div does not fade out at all.

推荐答案

您在 controller 中指定了应用名称.检查一下.

You specified your app name in controller. check this.

var testApp = angular.module('testApp', []);
testApp.controller('testController', function($scope) {
  $scope.obey = function test(id) {
    $scope.hide= !$scope.hide;
  };
});

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="testApp" ng-controller="testController">
  <div id="bla">
    <button ng-click="obey('bla')">Close</button>
    <h4 ng-hide="hide">Bla bla bla</h4>
  </div>
</div>

这篇关于角ng-click不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆