Angular UI / Select2 sometimes not loading "model"

  1. The goal: Get a Select2 control with wich I can add one or more industry to customers.
  2. What I have tried: see this plunker http://plnkr.co/edit/tqSmiE?p=preview
  3. The problem: Sometimes the data already associated with the customers. i.e. the industry_id's it has in it's industries property are not loaded/ used by select2. It might require several manual reloads to see it, but for me it happens every 2-5 reloads.
  4. Screenshot of expected behavior: Screenshot of expected behavior

  5. Screenshot of faulty behavior: Screenshot of faulty behavior

  6. Third possibility, also faulty: Third possibility, also faulty

How about this plunker

Use watch to make sure industries is loaded ?

The problem seems to be that sometimes the industries json is loaded after the customers json. When the customers array is repeated the industry_id's don't exist yet in the industries array and are discarded by Select2.

I believe the solution thus lies in making sure the industries array is available before the customers array get's ng-repeated. The question now is: how?