简体   繁体   中英

How to Call Controller Function From jQuery If Using Strict DI

In my current application I already called many AngularJS controller function from jQuery but I just started using strict-di directive and now its giving me an error that angular().element() not defined something like this.

I searched too much about this issue on Angular site and StackOverflow as well but didn't find any solution, I have 30-40 controllers and in all somehow I call function from jQuery so I can't change it is there any way to keep my all codes and also use strict-di ?

Also using :

app.config(['$compileProvider', function ($compileProvider) {
      $compileProvider.debugInfoEnabled(false);
    }]);

and getting undefined error in :

var myVar = angular.element(document.getElementById('ControllerID')).scope().FunctionName();

TIA

I don't think strict-di is your problem.

As per the documentation for scope() - https://docs.angularjs.org/api/ng/function/angular.element > jQuery/jqLite Extras > Methods > scope()

...Requires Debug Data to be enabled.

Your

$compileProvider.debugInfoEnabled(false);

disables Debug Data and so scope() on angular.element(document.getElementById('ControllerID')) returns undefined.

Try setting

$compileProvider.debugInfoEnabled(true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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