I'm working on a angular app which I do not have access to the source of the app only to the component html code. I want to re-order a array with a custom function, but I'm not sure it's possible to access global variables within the template.
This works and sorts the fields by the value of "name" property.
<div ng-repeat="$field in $fields | orderBy:'name' track by $field.name " >
<input ng-model="$item[$field.name] " />
</div>
If I try this, this will not work
Not Work
<script>var orderByProperty = 'name'; </script> <div ng-repeat="$field in $fields | orderBy:orderByProperty track by $field.name " > <input ng-model="$item[$field.name] " /> </div>
How can I access a global variables from within the angular template?
I do not have access to the controller code of the app or main js file of the app, only to the html of component. A solution how to order the array within the template will also solve this issue.
you can use ng-init to add some variables in html as: