Ng-click不在div中工作

时间:2022-10-22 09:11:25

I've got a menu that appears when I click on a button. Well, into that menu, I have pairs of spans: icon-title. Pretty straightforward, I guess.

我点击一个按钮时会出现一个菜单。好吧,进入那个菜单,我有两对跨度:icon-title。我想这很简单。

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. 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.

目前,我只关注“removeNote()”函数。我已经准备好测试角度和节点方法,但我不能使用它们,因为我无法执行点击。

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? Am I missing something?

为什么ng-click不会调用此函数?我错过了什么吗?

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控制台中看到它)。

1 个解决方案

#1


0  

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会给你一些东西吗?

#1


0  

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会给你一些东西吗?