为什么service()方法没有官方文件? [英] Why service() method has no official documentation?

查看:152
本文介绍了为什么service()方法没有官方文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我越来越开始在AngularJS,我见人()服务VS厂()在谈论一个两难困境,但我无法找到关于第一个任何文件。

I'm getting started in AngularJS and I see people is talking about a "service() vs factory()" dilema but I cannot find any documentation about the first one.

所以,我们应该迫使我们自己使用的工厂()?或者它就像一个别名?

So, should we force ourself to use factory()? or it's just like an alias?

在此先感谢

推荐答案

有些句子我希望我读了,当我开始采用了棱角分明。

Some sentences I wish I had read when I started using angular.


  • 一个供应商是获取编辑的功能。而可注入在该状态下的配置块。

  • A provider is a function that gets newed. And can be injected into a config block in that state.

当要使用它的时间(即在别处注射) $ GET 被调用,并从返回值是你的供应商。

When its time to be used (ie. injected elsewhere) $get is called and the return value from that is your provider.

一个服务是获取编辑和多数民众服务的功能。

A service is a function that gets newed and thats your service.

一个工厂是获取编辑和执行的函数。它的返回值是你的工厂。

A factory is a function that gets newed and executed. Its return value is your factory.

三种不同的方面都只是区分在他们创建的方法。

The three different terms are just to differentiate the method in which they're created.

有一些很好的使用每个:

Some good uses for each:


  • 提供商:
    至于角库或API服务配置

  • 服务:一个类像的对象。也许对共享存储应用程序数据

  • 工厂:处理获取和数据的节能..也许到你的服务的数据检索对象。

这篇关于为什么service()方法没有官方文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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