2.1: MVC
Last updated
Last updated
Angular is a front-end framework. What's the difference between a library and a framework? Think of libraries as how it is named, a library. It is a collection of objects and functions/methods, that your application links to in order to be used.
Frameworks include everything needed for your application to work. It will bring in libraries, scripts, package managers...basically all the necessary items to create your app. Another way of looking at the differences would be with a library you call the code to make it work. With a framework, it defines how it will work...meaning it calls YOUR code.
Before we get into the basic building blocks, let's take a look at the main design paradigm of Angular, Model-View-Controller(MVC).
Model - Contains the pure data for the application. It can be used to create interfaces for classes or communicate with the database. When a model changes its state, the view is then automatically updated.
View - Presents the model's data to the user. It also displays the app's UI.
Controller - The interface between the Model and the View. It responds to events triggered by the view and activates the reaction based on the triggered event. Typically, the reaction is method call on the model. The controller either renders a view template or communicates with model.
image from Wikipedia
Angular uses a component based approach to achieve MVC architecture. First, the Model is represented through the services that are injected into the component class through Dependency Injections. Second,the Controller is shown through the Component class using TypeScript. Lastly, the View is bound to the Controller by the HTML file. Don't worry, all of this will make more sense as we move forward.