Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

use route to lazy load controller js,on routeChangeStart add resolve attr to route

$routeProvider.when '/calendar',
      templateUrl: 'view/app/schedule/calendar.html', require:['javascript/controller/schedule']

     $rootScope.$on('$routeChangeStart', (e, target) ->
          route = target && target.$$route
          if route && target.require
            route.resolve = route.resolve || {}
            route.resolve.require = ->
              defer = $q.defer()
              require target.require, (controller)->
                $rootScope.$apply ->
                  defer.resolve()
              defer.promise
        )
    #javascript/controller/schedule.js
    define ['controller','angular-ui-calendar'], ->
      'use strict'
      #common controller
      angular.module('controller')
      .controller 'CalendarCtrl',($scope)->
        $scope.test='hi'
      .controller 'ScheduleCtrl', ($scope)->
        $scope.a = 1

    #page {{test}},baby not show test
    ,baby

    #if i  config controller
    $routeProvider.when '/calendar',
          templateUrl: 'view/app/schedule/calendar.html', controller: 'CalendarCtrl', require: ['javascript/controller/schedule']

i got Error: [ng:areq] http://errors.angularjs.org/1.3.0-beta.8/ng/areq?p0=CalendarCtrl&p1=not%20aNaNunction%2C%20got%20undefined

share|improve this question
    
why?Do you know how to solve? – 王仁辉 Aug 20 '14 at 3:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.