Angular-Browserify + ui.router - States生成" Uncaught object"

时间:2014-06-20 09:10:16

标签: angularjs coffeescript

我有一个项目需要比大多数专门用于小型项目的角度浏览器播种机更好的结构。是否有可能有一个需要所有路线的索引?例如this (which is on RequireJS)

我的项目正在使用gulp.js和coffeescript

我的项目结构

- assets/
    - bower_components/
    - coffee/
        - directives/
            - login.coffee
            - registration.coffee
        - services/
            - auth.coffee
            - user.coffee
        - utils/
            - states/
                    - auth.coffee
                    - dashboard.coffee
                    - index.coffee
                    - main.coffee
                    - modules.coffee
                    - otherwise.coffee
        - app.coffee
        - main.coffee

资产/ main.coffee

bootstrap = require '../bower_components/bootstrap-sass-official/vendor/assets/javascripts/bootstrap'
$ = require '../bower_components/jquery/dist/jquery'

$(document).ready ->
    angular = require '../bower_components/angular/angular'
    angular_ui_router = require '../bower_components/angular-ui-router/release/angular-ui-router'
    lumina = require './app'
    services = require './services/modules'
    directives = require './directives/modules'
    states = require './utils/states/modules'

    return

资产/ app.coffee

app = angular.module 'app', ['ui.router']

module.exports = app

资产/ utils的/州/ modules.coffee

otherwise = require './otherwise'
dashboard = require './dashboard'
auth = require './auth'
main = require './main'
index = require './index'

资产/ utils的/州/ auth.coffee

app = require '../../app'

app.config [($stateProvider) ->
    auth = 
        name: 'main.auth'
        abstract: true
        resolve:
            auth: AuthSrvc ->
                return AuthSrvc.check()

    $stateProvider.state(auth);
]

/assets/utils/states/dashboard.coffee

app = require '../../app'

app.config [($stateProvider) ->

]

/assets/utils/states/index.coffee

app = require '../../app'

app.config [($stateProvider) ->
    index =
        name: 'main.index'
        url: '/'
        resolve:
            auth: AuthSrvc ->
                return AuthSrvc.check()

    $stateProvider.state(index)
]

/assets/utils/states/main.coffee

app = require '../../app'

app.config [($stateProvider) ->
    main =
        name: 'main'
        abstract: true
        templateUrl: '../views/main/template.html'

    $stateProvider.state(main);
]

/assets/utils/states/otherwise.coffee

app = require '../../app'


app.config [($urlRouterProvider) ->
    $urlRouterProvider.otherwise '/'
]

当我尝试加载我的状态文件时,我会收到一个"未捕获的对象"错误。我不明白为什么。

1 个答案:

答案 0 :(得分:0)

这是由于没有注入依赖性。这就是我形成配置/状态/无论如何。

app.config [($stateProvider) ->
    auth = 
        name: 'main.auth'
        abstract: true
        resolve:
            auth: AuthSrvc ->
                return AuthSrvc.check()

    $stateProvider.state(auth);
]

注意第1行,其中我注释了缩小的依赖关系。我没有同样注释依赖:app.config [ '$stateProvider' , ($stateProvider) ->