是angular2 mvc吗?

编程入门 行业动态 更新时间:2024-10-23 13:35:14
本文介绍了是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吗?

本文发布于:2023-11-15 10:32:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1593642.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:mvc

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!