51212 (1) [Avatar] Offline
#1
I find that chapter 5 is a bit to the general side, where the text is mostly covering self-explaining source code.

Don’t get me wrong I like the drag/drop example, I am just missing some of the Angular specific details, like:

- What goes in the link function and what goes in the controller? (guidelines?)

- Is it considered good praxis to pass the element back to the controller and set css classes and other view specifics in the controller?

- I thought that jQuery stuff belonged inside directives or is it just as well to place this in controllers?
Lukas Ruebbelke (107) [Avatar] Offline
#2
I think you raise some valid points and thanks for sharing them. I had to make some difficult concessions on just how much to cover and how far to go with each topic. I had to reconcile this by focusing on creating a really solid sample application that would serve as additional commentary outside the book as well as engaging readers to talk about any parts that were not clear.

So to answer your points.

What goes in the link function and what goes in the controller? (guidelines?)

I think these two parts of the book offer pretty good explanations but I am happy to expound on any of this if you would like.

https://www.dropbox.com/s/gsjyojqavbk37ds/Screenshot%202015-06-17%2011.34.45.png?dl=0

https://www.dropbox.com/s/opb6etn2hb724p2/Screenshot%202015-06-17%2011.35.17.png?dl=0

Is it considered good praxis to pass the element back to the controller and set css classes and other view specifics in the controller?

Traditionally that was done only in the link method but you can now access the element from the controller via the $element parameter. So this is a topic that is a bit fuzzy and so I try not to turn this into a religious argument. I would recommend writing fine-grained, single-purpose methods that are easy to test i.e. clean code practice.

I thought that jQuery stuff belonged inside directives or is it just as well to place this in controllers?

DOM manipulation belongs in directives almost ALL the time. There are a few edge cases where you will sometimes see it happen in a service such as modal management but this is rare. With that said, you can now do DOM manipulation within the link or controller method inside the directive. But! Never ever do DOM manipulation in a general controller.

Please let me know if you want to clarify further. Happy to help!

201761 (1) [Avatar] Offline
#3
Chapter 5 seems to be in progress, and I have another opinion on it.

You did a wonderful job, introducing concepts steps by steps, explaining every instruction very clearly. I wish I had such a gift !

But suddenly, on the drag and drop directive, everything changes : 3 directives, tons of code, poor explanation, which have a probability close to zero to be run for a beginner on his app..... the effect is dreadful

Then hopefully the Flot directive goes back to normal.

An example about a directive returning "template", which is introduced in the first chapter should be welcome. I guess it is in progress.

I know that this book is for beginners and seasoned guys. I suggest that this drag and drop directive should be move to an appendix.

It is just a suggestion. Your book is still great !
Lukas Ruebbelke (107) [Avatar] Offline
#4
Thanks for the feedback! The drag and drop example was ambitious and a bit harder than I imagined to get right. It is definitely an advanced directive!

I believe that is by far the hardest thing I tackled in the book and so hopefully everything returns back to "normal" for you. #highFive
george.jiang (38) [Avatar] Offline
#5
It is actually the best example code to learn drag and drop with AngularJS in any AngularJS books out there. The author could have added more explanation in a second edition. Unfortunately, Google had killed AngularJS (aka Angular 1.x) with a completely different framework (aka Angular 2, which has been under development for two years but still does not have a release candidate smilie).