为什么 AngularJS 被认为是 MV* [英] Why is AngularJS considered MV*

查看:54
本文介绍了为什么 AngularJS 被认为是 MV*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾在后端 (Rails) 上使用 MVC,目前我在前端 (Angular) 上使用 MVC(MV*).我已经看到 Angular 被认为是一种 MV* 模式,但为什么会被认为是这样?

I have worked with MVC on the back-end (Rails), and am currently working with MVC(MV*) on the front-end (Angular). I have seen Angular as considered an MV* pattern, but why is it considered that exactly?

使用 Angular,我理解关注点分离、视图(模板)、控制器,并使用服务来提供数据.在这种情况下,通过 ng-model 的模型(数据存储)对于前端临时存储有意义,但实际的持久性(当对 API 进行 POST 或 PUT 时)似乎是通配符.由于数据的持久化方式,可以进行不同的处理(数据库、firebase 等).

Using Angular, I understand the separation of concerns, with Views (templates), Controllers, and use Services to serve up data. In this case, the model (data store) via ng-model makes sense for front-end temporary storage, but the actual persistence (when a POST or PUT is made to an API) seems to be the wildcard. As the way data can be persisted, could be handled differently (database, firebase, etc..).

根据我的理解,在我看来 *VC 更合适,因为 Angular 中的控制器比模型定义得更好.

It seems to me that *VC is more appropriate based on my understanding, as Controllers in Angular are better defined than Models.

必须有一些关于 MV* 模式的核心是我遗漏或困惑的,非常感谢任何澄清.

There must be something core about the MV* pattern that I am missing or confused about, any clarification is greatly appreciated.

推荐答案

以下是在 Angular 中选择 * 的几种方法:

Here are a few ways * can be chosen in Angular:

  • 控制器:

  • Controller:

$controller

查看模型:

指令属性

主持人:

展示-抽象-控制器

重要的是 UI 和模型是共同点.在不破坏应用的情况下构建有趣的 UI,在不破坏 UI 的情况下构建有趣的业务逻辑.

Important thing is that UI and Models are the common denominator. Build interesting UI without breaking app and build interesting business logic without breaking UI.

参考资料

这篇关于为什么 AngularJS 被认为是 MV*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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