Angular Meteor load order issue with filter or services


#1

I am looking for a solid solution for the load order of my files of my Angular Meteor project.

I have the current folder structure:

[root]
   client
      lib
      modules
        directives
        forms etc..
      startup
      styles
      views
   lib
     collections
   server
     methods
     publisher

My angular app is defined in client/lib/app.js.
I created a service which would be client only and I put that in `client/lib/services/someService.js’

Now because it is a subfolder it will be loaded first and it will throw an error that angular is not defined. So, then I renamed app.js' to00_app.js’ and the service to 01_someService.js to force the order.
This didnt work in my case (probably because I bootstrap the app with onReady -> angular.bootstrap.document, [ 'appname' ] )

I fixed it for now by putting the service in `client/modules/services/…’.
However, I rather put it in Lib cause modules is more for re-usable modules and widgets.

Also, when I want to define a service that is used server and client, would put it in [root]/lib/services... This would create the same load issue because Angular is not yet defined. I don’t want to use isClient or isServer in the service files.

I had another issue today where I add a filter to the [root]/lib/filters directory. It loads before the client/lib/app.js is loaded. and throws the ‘Angular is not defined’ error. It is very annoying.

Is there an elegant solution for this?


#2

I found one workaround for which works but is ugly, I use the angular.element(document).ready function to test if angular is available.

So in my `client/lib/controllerFile.coffee’ I would have the code

angular.element(document).ready ->
  angular.module( 'myApp' ).controller 'myCtrl',
    ($rootScope,$scope, $meteor, $state , $stateParams, $mdToast ) ->
        console.log(arguments)

This works.

My app.coffee which defines the angular app / module is in `client/lib/app.coffee’. Unfortunately subfolders are loaded first.
I don’t recon I would have to place the app in a subfolder???