AngularJS +how to wait for task to finish before running next task
<p>I have still problems with my database, but I found out, that the problems come from the fact, that opening the database takes some time, but the app is not waiting till this task has finished.</p>

<p>Is there a way to make angular wait till the database is opened correctly before it starts the next task?</p>

<p>Thanks,
Christian.</p>

<hr>

<p><strong>Update: 2016-08-08 - 03:13 pm</strong></p>

<p>Thanks for all the answers. As I can see, my first idea with promises ($q) was right, but:</p>

<p>My app has an app.js, which is my main file. It only calls the InitDB. This should open the database. Then it should call the CreateTables, this creates the table, if it doensn't exist.</p>

<p>The rest of my app is splitted in 4 pages (templates). Every page has it's own controller.</p>

<p>So the idea was to init the db, to create the table, and then work with the database, but used over different controllers.</p>

<p>This won't work, because I would always need to put all of my stuff in the .then() of my initDB in the app.js???</p>

<p>This is my first AngularJS app, maybe this is the reason why I do a lot of mistakes...</p>

<p>Thanks,
Christian.</p>