简体   繁体   English

Ng-click在div中不起作用

[英]Ng-click not working in div

I've got a menu that appears when I click on a button. 当我单击一个按钮时,会出现一个菜单。 Well, into that menu, I have pairs of spans: icon-title. 好吧,在该菜单中,我有两个跨度:icon-title。 Pretty straightforward, I guess. 我猜很简单。

Well, somehow, these spans don't call my controller method when I click on them. 好吧,以某种方式,当我单击它们时,这些跨度不会调用我的控制器方法。 I tried wrapping these pairs in divs and setting the ng-click on them, but that does not work either. 我尝试将这些对包装在div中并在它们上设置ng-click,但这也不起作用。

This is my contextual menu: 这是我的上下文菜单:

<div class="opciones" ng-hide="optionsHide">
      <div>
        <span class="glyphicon glyphicon-lock icono"></span> <span class="optionsLabel">Encrypt</span>
      </div><br>
      <div ng-click="removeNote()">
        <span class="glyphicon glyphicon-trash icono"></span><span class="optionsLabel">&nbspDelete</span><br>
      </div><br>
      <div>
      <span class="glyphicon glyphicon-wrench icono"></span><span class="optionsLabel">&nbspOptions</span>
      </div>
    </div>

Currently, I'm only focused on the "removeNote()" function. 当前,我仅关注“ removeNote()”函数。 I've got both angular and node methods ready to test, but I just can't use them since I can't perform the click. 我已经准备好测试角度和节点方法,但是由于无法执行点击,所以我无法使用它们。

This is the function, inside the working controller: 这是工作控制器内部的函数:

    $scope.removeNote = function(){
      $http.post('/removeNote', $scope.mainNote).success(function(data){
        console.log("Note removed");
        console.log(data);
        loadNotes();
        }).error(function(err){
          console.log("ERROR ON DELETE");
          console.log(err);
          });
    }

Why ng-click does not call this function? 为什么ng-click不调用此功能? Am I missing something? 我想念什么吗?

edit: 编辑:

Controller declaration: 控制器声明:

Upper controller: 上位控制器:

 app.controller('mainCtrl', ['$scope', '$http', '$filter', 'focus', function($scope, $http, $filter, focus){

Inner: 内:

app.controller('contentCtrl', ['$scope', '$q', '$timeout', function($scope, $q, $timeout) {

Use: 采用:

<body ng-controller="mainCtrl" ng-cloak>
    // Things
     <content ng-controller="contentCtrl">
     // My contextual menu as shown above

Actually, this method is inside another controller (yes, two nested controllers), but the rest of inherited functions work properly; 实际上,此方法在另一个控制器(是的,两个嵌套的控制器)内部,但是其余继承的函数可以正常工作。 the only one that is not working is this one. 唯一不起作用的就是这个。 Anyways, I keep seeing the normal pointer when I put the mouse on my div/pair of spans, so it's not being applied at all (I can see it in the HTML console tho). 无论如何,当我将鼠标放在div /一对跨度上时,我总是看到普通的指针,因此根本没有使用它(我可以在HTML控制台中看到它)。

Try altering your ng-controller line: 尝试更改您的ng-controller行:

<body ng-controller="MainCtrl as vm">

Then your method call: 然后您的方法调用:

<div ng-click="vm.removeNote()">

Does it work now, does the console.log give you something? 现在可以正常工作了吗,console.log可以给您一些东西吗?

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

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