Ember-CLI:如何在coffeescript中编写初始化程序?

时间:2014-10-09 01:25:41

标签: ember.js coffeescript ember-cli

我使用Ember-cli生成了一个应用程序。我已经创建了一个初始化程序,但我遇到了一个问题。

我收到了错误:

Uncaught TypeError: Cannot read property 'name' of undefined

应用程序/初始化/ user-auth.coffee

`import Ember from 'ember'`
`import Base from 'simple-auth/authenticators/base'`

SFDCAuthenticator = Base.extend(
  # auth here
)

SFDCInit = Ember.Application.initializer(
  name: 'authentication'
  before: 'simple-auth'
  initialize: (container, application) ->
    container.register 'authenticator:custom', SFDCAuthenticator
)

`export default SFDCInit`

1 个答案:

答案 0 :(得分:1)

您需要从初始化程序导出对象,不要使用Ember.Application.initializer

像这样的东西

`import Base from 'simple-auth/authenticators/base'`

SFDCAuthenticator = Base.extend(
  # auth here
)

SFDCInit =
  name: 'authentication'
  before: 'simple-auth'
  initialize: (container, application) ->
    container.register 'authenticator:custom', SFDCAuthenticator

`export default SFDCInit`