I have a lot of jQuery background and am currently getting into angular.
So far I have resisted the urge to include jQuery to get things done the way I used to.
I would like really learn to do things the angular way.
Here are some things I ran across and I would really like the opinion of some angular professionals on them:
Adding user interactions.
Standard scenario: If the user does this, do that.
Should I create directives for each case or add methods to the controller?
How do I decide wether to make a directive out of it or just a controller method?Adding the same functionality to multiple elements
Presume I have a bunch of divs spread out over the page, or even just several cols of a table.
In jQuery if I wanted to do something, when the user clicks on any of them I would just do$('div').click(...)
or$('#mytable th').click(...)
In angular the only way I know how to do this is the ng-click directive, which results in very verbose code, when adding this directive to every single element.
Especially since I thought angular was supposed to make code more readable I was wondering if there is a better solution to that.Separation of Code
One of the things I like about angular is the effort to keep html in html files and the js in js files. This was actually one of the things that most annoyed me with jQuery.
But the way directives are set up sort of contradicts this. Here you define some template html code (or link a template file). The same goes for user interaction handlers (i.e. user clicks this -> display that message).
So in the end I end up again sifting through code to find out where that particular piece of html code comes from. Am I missing something here?MVC
In most of the examples out there the model is defined inside of the controller.
Shouldn't it be defined somewhere else for true MVC separation? What about for example always creating a service for the model, since often at least parts of the model are loaded by services anyway? Or am I overstepping the mark here?app.js
This is more of a side note: I find it confusing that for both node and angular the convention is to call the main file 'app.js'. If I have both files open in my editor I have to click through them to see which is which. I know I can name then however the hell I want but as I said I'd like to do things right and am just wondering if this never bothered anyone else... Maybe angular should consider enforcing the convention "app_ng.js" or something...?
Please post your thoughts as answers, not comments, for readability purposes.
thank you,
Jan