骨干式模型angularjs? [英] backbone-style models in angularjs?

查看:185
本文介绍了骨干式模型angularjs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我道歉,如果这个问题已经回答了其他地方,但我找不到一个完整的,明显的(对我来说,至少)解决方案。

I apologize if this question has already been answered elsewhere, but I couldn't find a full, obvious (to me, at least) solution.

我有骨干模型的想法的经验。在我看来,这是类似于其他任何OOP语言类 - 创建一个阶级使用Backbone.Model.extend(),当你想这个类的一个新实例上调用它新的。如果我有一个应用程序的命名空间,我可以存储所有我的对象那里,像做App.getAllThisOrThatTypeModel()。

I have experience with the idea of a Model in backbone. In my mind, it's similar to a class in any other OOP language - create a "class" using Backbone.Model.extend(), and call new on it when you want a new instance of that class. If I have a app namespace, I can store all of my objects there, and do something like App.getAllThisOrThatTypeModel().

这是在角服务?它是一个确定的最佳做法有服务的LOT(每个类型的模型),基本上是模仿类和服务?

Is this a service in angular? Is it an ok "best practice" to have a LOT of services (one for each type of model), basically mimicking "class" with "service"?

我只是想换我周围的最好办法头处理模型作为我试图从骨干角移植到实验 - 有人在这个方向迁移任何建议将不胜AP preciated

I'm just trying to wrap my head around the best way to deal with models as I try to migrate from backbone to angular to experiment - any advice for someone migrating in this direction would be greatly appreciated.

谢谢!

推荐答案

在角模型只是的POJO(简单的JavaScript对象)。

In Angular models are just a POJOs (plain old javascript objects).

服务是不同的东西,但你通常会提供服务获取模型。这是一个很好的做法,有更多的服务,让您可以在整个应用程序中重用他们。也为服务大加是,他们可以进行单元测试。而像软件工程一切,它总是更好地将应用程序划分成更易于维护比code的一大吸盘小模块。

Services are something different, but you'll usually fetch the models with services. It is a good practice to have more services, so you can reuse them throughout your application. Also a big plus for services is, that they can be unit tested. And like everything else in software engineering, it's always better to split your application into little modules which are easier to maintain than a big chucks of code.

您不必只是模仿你的模型作为服务。以后,您可以添加一些功能给他们,并保持这些服务里面域的逻辑。

You don't need to just mimic your models as service. You can later add some functions to them and keep your domain logic inside those services.

我不是一个专业的角度,但我希望这可以帮助。

I'm not an Angular specialist, but I hope this can help.

这篇关于骨干式模型angularjs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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