是angular2 mvc吗? [英] Is angular2 mvc?

查看:68
本文介绍了是angular2 mvc吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾在Angular 1工作.它显然有一个控制器,它充当View和Model之间的中介.我意识到在Angular 2中我们没有任何控制器.

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.

那么我们仍然可以将Angular 2称为MVC框架吗?我知道MVC是一种设计模式,您可以用任何语言来实现它.但是,关于Angular 1,我从很多人那里听说这是一个MVC框架,并且我看到的大多数示例都清楚地表明Angular 1是MVC,并且Controller将Model与View分开.所以,我想知道,既然Angular2中已经有了Components,我们还能称其为MVC吗?或因为组件本身遵循MVC范式,因为我确实看到在每个组件中我们都将视图和数据分开并使用绑定,也许我们仍可以将其称为MVC.

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 2更多地是基于组件的体系结构.您可以将所有内容都假定为组件,例如指令,服务等. 尽管指令和服务实际上是为基本组件提供支持的,但是它们也以类似的方式定义. 基本组件包含依赖项,视图详细信息和类声明,可以将其视为控制器. 因此,定义良好的组件由MVC体系结构的各个集合组成.

Angular 2 is more of 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 similar fashion. A base component contains of dependencies, a view details and class declaration which may be considered as controller. So a well defined component consist of individual set of MVC architecture.

例如(角度2 alpha版本):

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 {
}

}

在上面的示例中,您可以看到可以将类"home"假定为控制器,View是使用@View装饰器编写的.组件自定义由@component装饰器提供. 您还可以看到不同的依赖项注入实践.

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.

: 示例(当前的角度2/4版本)

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 {}

简而言之,angular 2是基于组件的MVC框架.

In a nutshell, angular 2 is component based MVC framework.

这篇关于是angular2 mvc吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆