We want to call a angular component methods publicly through the Java script function.
All methods from an AngularJS Component should be declared in its $scope
. If that is your case, you should make a querySelector to get the html element that hosts the component you want, with that you can capture the angular scope as below:
var element = document.querySelector("<make a query here>");
var angularScope = angular.element(element).scope();
You now should be able to invoke any methods (and variables) from the component scope:
angularScope.yourMethod();
-
In our case the element is not present on the page. We want to call the component method from external javascript file. We are using angular v6 – Stelma Rebello Nov 22 '18 at 10:28
-
I thought I had understood what you're asking for. Now I'm not sure anymore. If the component isn't in the page, why would you want to call it's methods? – Pedro Lima Nov 22 '18 at 10:32
call a angular component methods publicly through the Java script function
? – Pardeep Jain Nov 22 '18 at 10:08