0

First of all, thanks for this great plugin! (to the author of angularAMD)

I have some troubles. I have all modules loaded with ngAMD but two are inside my index.html because are templates and I'm including this way:

 <div ng-include="'views/header.html'"></div>

header.html uses HeaderCtrl but I have no idea how load before angularAMD.bootstrap...

More code:

header.coffee that requires app

define ['app', 'bootstrap'], (app, bs) ->
  'use strict'

  app.controller 'HeaderCtrl', ($scope, $rootScope) ->
    $scope.searchText = "";

    $scope.updateSearch = -> 
      $rootScope.searchText = $scope.searchText;

app.coffee

define ['angular', 'angularAMD'], (angular, angularAMD) ->
  'use strict'

  app = angular.module 'testsApp', [
    'ngRoute'
    'localization'
    'restangular'
  ]

  angularAMD.bootstrap app
  app

After bootstrapping app, ng tries to solve ng-include but HeaderCtrl is not loaded! This happens only with CTRL+F5 on page, it's a matter of loading time. I have no idea on how solve this. Any hint?

2
  • Are you still having problem? If you do, setup a simple plunker and I will see what I can do to help. Commented Jan 7, 2014 at 11:12
  • @marcoseu : thanks. I've solved. I'll put the solution online ASAP. Commented Jan 7, 2014 at 13:27

1 Answer 1

2

The problem was angularAMD.bootstrap app position. I was bootstrapping before loading each dependencies.

I moved angularAMD.bootsrapp call after dep loading and all works now:

bootstrap.coffee (the application bootstrapper)

define [
  'app'
  'jquery'
  '_'
  'angularAMD'
  'ctrl/header'
  'ctrl/menu']
, (app, $, _, angularAMD) ->

  # bootstrapping all dependencies
  $.get "modules/modules.json", (deps) ->
    # converts all array items from DEP to module!DEP
    deps = _.map deps, (dep) ->
      "module!#{dep}"

    console.log JSON.stringify deps
    require deps, ->
      console.log "Dependencies loaded!"
      # I'll bootstrap angular only after each dependencies are loaded, this prevents many 'random' issues.
      angularAMD.bootstrap app

I hope this can help someone :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.