3

I am new to Ember and the assignment I am working on is using 1.11 version already. I used to work on Angular and am finding myself confused with some concepts here in Ember. Read that Controller is used for logic and deals with data whereas Component (js) deals with the behavior of component

So, the doubt I have is

1) Where should i be doing my DOM manipulation

2) In case I need to modify/play my json data, after I get from server is controller the right place or the respective component?

2 Answers 2

3

1) Where should i be doing my DOM manipulation

If you are able to move this to component (when designing your logic) it would be definitely more appropriate place than controller.

2) In case I need to modify/play my json data, after I get from server is controller the right place or the respective component?

Best solution would be to fire actions from components and those actions should be handled in controller where you can manipulate your JSON that you probably obtain in routes and pass it along to controllers via model.

Sign up to request clarification or add additional context in comments.

2 Comments

Hey, thanks for that. As a follow up on that, what kind of code generally goes into component js file then. Would you have any references which could help me with.
Ember Views that generally were place for such DOM manipulations if necessary have been replaced by Components, so you can look at Components as they were V of MVC pattern (I know Ember has slightly different pattern, but still).
2

Why do you use such an old version of ember? Current LTS version is 2.4, and release is 2.6.

There questions highly changed since ember 1.13.

To answer you questions:

  1. You should never do DOM manipulation manually. Use the handlebars template for that. If you absolutely have to the right place is only the didInsertElement hook of the component, or view in earlier ember versions.

  2. The best way to modify your server data is a serializer! To calculate additional data use computed properties on the model, component and controller.

Generally only use controllers as last choice. There are some use cases where you have to use them, but not many.

2 Comments

I have just joined the project and have asked to upgrade. I think I agree with the dom manipulation point. But in case I have data which I need to play with, for e.g. sort, calculating values based on data, wouldnt the component (js file) be more appropriate than controller.
It actually doesn't make a different. Think about your controller/route template pair as a a bit limited controller with a few drawbacks. It actually should always be easy to migrate from a controller to a component. But I would prefer components.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.