AngularJS - ng-init w/ ng-repeat not working but hidden div does

546 Views Asked by At

Any idea how to get this to work?:

<div ng-repeat="item in editable_values" ng-init="val = edit_data[item]">

From what I can tell, val is always undefined, based on {{val}} not displaying anything. I'm guessing that ng-init is running when editable_values is defined, but I actually need it to run when edit_data changes.

This does work, but feels hacky:

<div ng-repeat="item in editable_values">
    <div ng-show="false">{{val = edit_data[item]}}</div>

editable_values is a list of keys

edit_data is an object

editable_values is defined at creation time in the controller, while edit_data isn't defined until the user clicks on something to edit. The div that acts as a container for the ng-repeat in question isn't actually visible until a user clicks on something to edit.

The ng-repeat used to be (item, val) in edit_data, but I needed to sort the keys in a specific order.

0

There are 0 best solutions below