Top 5 Guidelines Every Angular Developer Must Follow
From our previous article, we understood Why developers choose Angular technology in their project. In this blog, we will discover some key guidelines accommodating angular developers.
Guidelines to follow in Angular Project:
1) Never write the code for DOM manipulations in angular components, because angular is designed in such a way to do the same automatically based on the changes to application data.
For eg: if you update the value of the product price variable, the same thing will automatically update in the corresponding label on the page. In such a way we are making application logic only to manipulate data but not manipulate DOM directly. So, we can execute unit testing at any time.
2) Never write javascript code in angular templates, the angular templates that are HTML code will be converted into equivalent javascript code which provides DOM at run time. So, if we place javascript code in the angular template it will not compile properly by the angular compiler.
3) Never write business logic in components, because components are designed to store application data in the form of array or properties, also necessary provisions necessary event handlers to the templates.
Components are never intended to hold business logic, this business logic should be written in services and be invoked in the components. Business logic contains services to become independent of user interface and can be reusable across the application.
4) Never using Jquery to manipulate DOM elements. In angular we should not use jquery to perform DOM manipulations such as getting, setting textbox values. But however, we can make use of limited jquery code for some plugins such as drag&drop, modal popups, etc.
5) Always make ajax calls to rest API services in angular services only, because it is a part of business logic, and return observables from angular service methods.
These are some guidelines all angular developers must follow, Would you tell us how you feel about this blog?