We’ve migrated our documentation to a new site, which means some URLs have changed.
Subscriptions

How to access Angular custom variables in pure JS

In order to access Angular custom variables in pure JS, you would need to add this to your template's code (or add any other element you can reference or use an existing one as well if preferred):

HTML
<div  id="custom-field"  class="hidden">
</div>

And then you add this to the bottom of your template's code:

HTML
<div custom-script>
    var dom_el = document.getElementById('custom-field');
    var ng_el = angular.element(dom_el);
    setTimeout(() => { console.log(ng_el.scope()["custom"]["fullName"]);}, 500);
</div>

You can access custom variables through the following code:

ng_el.scope()["custom"]["fullName"]

You can also adjust the timeout length if needed. In the above example, it's set to 0,5 seconds.

Last updated: