ember.js - How to properly inject property into controller -
This was my initial approach but I get an error code:
amber. Start ({name: "currentUser", initialize: function (container, application) {var store = container.lookup ('store: main'), attributes = $ ("meta [name = 'current-user']") attr ('Content'); if (attributes) {var object = store.push (App.User, JSON.parse (attributes)), user = App.User.find (object.id), controller = container.lookup (' Controller: Current User '). Set (' Content ', User); Container Type Injection (' Controller ',' Current User Narrator ',' controller: current user ');}}}); Error:
Error: Controller on other Controller (Controllers): Current-user 'can not inject. Register 'Controller: Current-User' as a different type and type inject. So I did something after the start of the "Store", after
Ember.Application.initializer ({name: "currentUser",) Methods): Function (container, app) {var store, user, proxy; Var attributes = $ ("meta [name = 'current-user']"). Attr ('content'); If (attributes) {application.deferReadiness () (container. Lookup ('store: main'). (Search for 'user', object.id). Then (function (user) {application.register ('user: current', User, {instantiate: false, singleton: Application.inject ('route', 'currentUser', 'user: current'); application.inject ('controller', 'current user', 'user: current'); application AdvanceReadiness ();}, function () {application.advanceReadiness ();}}}}}}}); It does not make any errors, but it also works properly I do not seem to be in
I try The other way of doing this was
amber. Application.Inventor ({name: "current user", then: "store", start: function (container, app) {var store, user , Proxy; var attribute = $ ("meta [name = 'current-user (' content '); if (attributes) {application.deferReadiness (); store = container.lookup (' store: main '); proxy = app Current User ObjectProxy.andend (); Container.Register ('User: Current', Proxy, {Altton: True }); Proxy = Container.Lux ('User: On'); Var object = store. Push (app users, json npares (specialty)) store.find ('user', object.id). Then (function (user) {proxy .set ('content', user); application.inject ('controller', 'current user', 'user: on'); application. Advanceadence ();});}}} ); In a different file
app. Current User ObjectProce = Amber.ObjectProxy Add ({content: tap}); What I'm trying to do to debug this problem, log in the currentUser name on the application template
{{logs turned on User.firstName}} I can see in my Amber Inspector that the data is being properly added for the user, it is not setting up correctly on the current user's property controller, What I should do is call already a ObjectProxy in the calling search Call can and set your injectors. Ember.Application.initializer ({name: "currentUser", followed by: "ember-data", initialize: function (container) (application) {var store, user, proxy; var Attributes = {id: 1, name: 'foo'}; if (attributes) {store = container.lookup ('store: main'); store.push ('user', attributes); var user = store.find ( 'User', attributes.id); container.register ('user: current', user, {singleton: true, instantiate: false}); application injection ('controller', 'current user', 'user:') ;}}}); Example: If you want to be able to swap it on some future day you can use a pattern here (mentioned in my answer )
Example:
Comments
Post a Comment