Call AngularJS method from Javascript -


i using angularjs , typescript. there external library using , need call angularjs method library in vanilla javascript followed this example

but sadly did not work.

the error function (which in angularjs class) not function.

  var scope = angular.element( document. getelementbyid("mainwrap")). scope(); scope.$apply(function () {     scope.createsession(data); }); 

now have vm use in typescript?

following typescript code

module myctrl{  interface imycontroller{     createsession(); }  class mycontroller implements imycontroller{      constructor(         ){          var vm = this;       }      createsession(data){              console.log(data);     } }  angular.module('app').controller('myctrl', mycontroller); 

}

and here goes html

<section id="mainwrap">  </section> 

any ideas?

scope object angular uses bind template , controller. can use syntax controlleras rid of scope , use controller instance bind properties , methods of this, template. once scope of template have property named alias gave controller either on router/directive definition (controlleras: alias), or template ng-controller="myctrl alias". property controller instance can call method that:

 var scope = angular.element(document.getelementbyid("mainwrap")).scope();  scope.$apply(function () {     scope.ctrlalias.createsession(data);  }); 

but if possible encapsulate in directive don't need access angular components outside application


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -