I have worked in Angular 1.It clearly had a controller which acted as a mediator between View and Model. I realized that in Angular 2 we don't have any controller as such.
So can we still call Angular 2 as an MVC framework?. I know MVC is a design pattern and you implement it in any language. But, with respect to Angular 1, I heard from many that it is an MVC framework, and most of the examples that I saw clearly said that Angular 1 is MVC and Controller separates Model from View. So, I was wondering, now that have Components in Angular2, can we still call it as MVC? Or as Components by themselves follow MVC paradigm, because I do see that in each Component we do separate View and Data and use binding, maybe we can still call it as an MVC.
Angular framework is embedded with original MVC but it's more of an MVVM software architectural setup. Angular does not ask developers to split an application into different MVC components and build a code that could unite them.
Moreover, there was much confusion about whether Angular was really Model-View Controller (MVC) or Model-View-ViewModel (MVVM) . In reality, it was neither! Rather, Angular follows a component-oriented architecture. Having said that, Angular does share some of the concepts of both MVC and MVVM.
AngularJS is a MVC based framework.
Each Angular 2 application needs to have one Angular Root Module. Each Angular Root module can then have multiple components to separate the functionality. Following is an example of a root module. Each application is made up of feature modules where each module has a separate feature of the application.
Angular 2 is more of a component based architecture. You can assume everything as component, like directives, services and so on. While directives and services are actually for the support of base components, they are also defined in a similar fashion. A base component contains dependencies, view details and a class declaration which may be considered as controller. So, a well defined component contain one set of MVC architecture.
for example (angular 2 alpha version) :
import {Component, View, bootstrap, provide, NgClass} from 'angular2/angular2'; @Component({ selector : "my-home" }) @View({ directives : [NgClass, EditSettingPanel], styles: ['.hidden{ display : none} .visible{ display : block}'], templateUrl : "views/blog-panel.html" }) export class home { } }
In the above example you can see that class "home" may be assumed as controller, View is written with @View decorator. The component customization is given by @component decorator. Also you can see different dependencies injection practice.
EDIT :: Example (Current angular 2/4 version)
import { Component } from '@angular/core'; @Component({ selector: 'custom-component', templateUrl: './template.html', styleUrls: ['./style.scss'], }) export class CustomComponent {}
In a nutshell, angular 2 is a component based MVC framework.
The components and directives are the controllers, the template (HTML) processed by Angular and the browser is the view, and if you don't combine the model with the controller, you get a MVC pattern.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With