CoffeeScript - Referencing DOM nodes in Angular expressions is disallowed

前端 未结 3 719
礼貌的吻别
礼貌的吻别 2021-02-05 00:19

My main question is simple :

I get errors when doing DOM manipulation within Controllers or Directives however, the functionality works perfectly.

Erro         


        
3条回答
  •  别那么骄傲
    2021-02-05 01:08

    Although the accepted answer is right I'd like to share my experience anyway as it turned out to be a different problem. In fact I had the same issue but I wasn't actually returning anything at all from my function (and not using CoffeeScript) so i was puzzled for a bit and struggled to find a solution.

    In my case the problem appeared to be that I was passing the DOM node as an argument to the function like so:

    
    

    What proved to be a solution here was changing the mentioned code to pass only the event and not the node directly:

    
    

    Then fetch the node in the controller/directive/whatever like so:

    doSomething = function(evt){
        var elem = evt.currentTarget;
        // do something with this element...
    };
    

提交回复
热议问题