I was including all of my angular code in $(function(){...});
and developed an app that is working fine. Then I came across a stackoverflow thread: How does document.ready work with angular element directives? which basically means that angular loads its modules already at 'document.ready' event, so I tried to remove all of the $(function(){...});
but everything just fails without it. How should the angular app be developed, with encapsulation of angular code inside of $(function(){...});
or without it? Why does the removal of the encapsulation in my code fails to work if angular itself does the thing?
Asked
Active
Viewed 35 times
0

Community
- 1
- 1

Nikita Vlasenko
- 4,004
- 7
- 47
- 87
-
1What do you mean by "fails"? What goes wrong? Is there an error in the console? – m59 Nov 03 '15 at 01:42
-
There are so many things that can go wrong when you refactor your code like that. Do you get any errors? – Thilo Nov 03 '15 at 01:42
-
In console I see `angular is not defined` all over the place + `[$injector:modulerr]` which states that my main module failed to be instantiated. I have `ng-app = 'simulator'` on the page in `html` tag. – Nikita Vlasenko Nov 03 '15 at 01:49
-
You're including the angular script in the wrong order. One of your dependencies is trying to register with angular before the `angular` global variable is available to it. You need to include the angular script prior to whatever that is (probably just include it first). If for some reason I am incorrect and this is not a duplicate, I'll reopen it. – m59 Nov 03 '15 at 01:56
-
Yes, that was the issue. Thank you! But why the question is marked as duplicate? I have not found any answers on stackoverflow. That's why I asked it. – Nikita Vlasenko Nov 03 '15 at 01:59
-
It is not really a duplicate: the underlying issue IS a duplicate, but not the issue I asked about. – Nikita Vlasenko Nov 03 '15 at 02:01
-
A new answer to your variant of the problem won't be helpful. Anyone that has your question should look toward the other post since the answer is the same. – m59 Nov 03 '15 at 02:04
-
By the way, the reason you weren't able to find the answer is important to note. You needed to search for the error "angular is not defined". It that yielded no result, then a question about that error is warranted... the linked question is the question you needed to ask. Remember to make your searches and questions detailed. That post originally had a poor title as well, but I updated it to make it more helpful. – m59 Nov 03 '15 at 02:11