注入控制器不在Emberjs中工作

时间:2014-04-15 09:43:23

标签: ember.js

我有一个Storage Ember对象,我注入routecontroller。我可以访问Storage中的route,但不能访问controller中的App.Storage = Ember.Object.extend #... #... Ember.onLoad "Ember.Application", (Application)-> Application.initializer name: "storage" initialize: (container, application)-> application.register "storage:main", application.Storage, singleton: true #Inject to both controller and route application.inject "controller", "storage", "storage:main" application.inject "route", "storage", "storage:main" #I can access `Storage` here in Route App.MessagesRoute = Ember.Route.extend setupController: (controller, model)-> console.log @get('storage') #OUTPUTS: Class {toString: function, __ember1397551513765: "ember299", __nextSuper: undefined, __ember1397551513765_meta: Object, constructor: function…} #But I can't access `Storage` here in Controller App.MessagesController = Ember.ArrayController.extend actions: createMessage: -> console.log @get('storage') #OUTPUTS: `undefined` 。 (Emberjs版本:1.5.1)

App.__container__.lookup('storage:main')
//OUTPUTS: Class {toString: function, __ember1397551513765: "ember299", __nextSuper: undefined, __ember1397551513765_meta: Object, constructor: function
App.__container__.lookup('route:messages').get('storage')
//OUTPUTS: Class {toString: function, __ember1397551513765: "ember299", __nextSuper: undefined, __ember1397551513765_meta: Object, constructor: function…}
App.__container__.lookup('controller:messages').get('storage')
//OUTPUTS: undefined

我还尝试在Chrome控制台上进行测试:

{{1}}

任何帮助都将不胜感激。

0 个答案:

没有答案