1

I am new to Ember.js and am trying to figure out how to piece things together at this point. One component I built, since I need a re-usable "widget" to use across many portions of my application, is a "site nav" widget. Basically, it's almost like the buttons/links you see in StackOverflow when you open a new question titled: "Questions Tags Users Badges Unanswered". In my app, these links have a name and id associated with them on the server-side. I want to be able to use this navigation widget on multiple parts of my app and it should be as simple as putting:

{{site-nav}}

into a template. I got that part working just fine, but the navigation is currently hard coded in handlebars. My question is, for a component, where is the right place to retrieve/populate model data from the server? For a controller, we do it directly from the controller's route definition. The component is not associated with a router. In fact, it can be re-used, as mentioned before, in several parts of the app.

I want to be able to drop this component into templates and have it populated with modeled nav from the server which has the name/IDs of the navigation I need. Where is the best place to do this? I'm guessing I'll still extend from something like DS.Model, but I'm not entirely sure where/when/how to integrate this with the component. When do I create the model and invoke a .find() type call to the server to populate site-nav with data?

randombits
  • 47,058
  • 76
  • 251
  • 433

1 Answers1

1

you can pass value to component Passing properties to component via handlebars.

{{my-nav navlist=listfromserver}}

so the list from server is in our controller can be passed to the component

Rigel
  • 882
  • 1
  • 11
  • 32
  • But the controller is associated with a different `model`. Are you saying there's a way to have it associated with both the `site navigation` AND its own respective modeled data? – randombits Apr 25 '14 at 19:25
  • you can get data from the that controller which has this data using controller dependencies. using needs : ['controller with navlist'] in current controller can you make a jsbin it will be easier for me to understand – Rigel Apr 25 '14 at 19:28
  • Not sure I'm getting this. Components aren't associated with any particular controller as far as I'm aware. That means using `needs` only makes sense if I need data from another controller. I'm just trying to make a re-usable component that has its own associated data. – randombits Apr 25 '14 at 19:32
  • there are multiple approaches. You can associate multiple models to one controller too. depends how your app is. you can check this out too http://stackoverflow.com/questions/20521967/emberjs-how-to-load-multiple-models – Rigel Apr 25 '14 at 19:32
  • well I too am learning ember and for components it written in docs " There is no access to the surrounding context or outer controller; all contextual information must be passed in." if a component has a controller and route how will it be different from normal view/template – Rigel Apr 25 '14 at 19:36
  • Hi if you think my answer is valid please make it accepted unless you wating for better answer. – Rigel Apr 26 '14 at 20:05