Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
722 views
in Technique[技术] by (71.8m points)

angular - Is angular2 mvc?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...