服务,指导和模块之间的区别

编程入门 行业动态 更新时间:2024-10-16 20:29:49
本文介绍了服务,指导和模块之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是新手,知道的基本知识,并试图在这真棒框架我的手。我一直在阅读了大量文档的,我越来越糊涂了。我基本上不能想出一个的区别

I am a newbie, know the basics and trying my hand on this awesome framework. I have been reading a lot of docs and I'm getting more and more confused. I basically can't figure out the difference between a

  • 服务
  • 指令
  • 模块

我看到很多自定义组件。有时,他们使用的指令,somtimes服务。它总是以模块开始。有人可以用一​​个例子有什么区别这三种类型之间的解释?

I see a lot of custom components. Sometimes they're using directives, somtimes services. It always starts with a module. Can someone explain with an example what the difference is between these three types?

推荐答案

作为是要连接其他的一些东西,比如指令,服务,常数等。模块一个地方模块想想可以注入到其他模块给你重用一个较高的水平。

Think of a module as being a place to wire up a number of other things, such as directives, services, constants etc. Modules can be injected into other modules giving you a high level of reuse.

在写一个角度应用程序,你将有一个顶层模块,它是应用程序code(没有模板)

When writing an angular app, you would have a top-level module which is your application code (sans templates)

服务主要控制器之间通信的方式,但你可以注入一个服务到另一个。服务经常被用来作为一种方式来获得您的数据存储和人民将包住角的API,如ngResource。因为它使测试(特别是嘲讽)很容易这个技术是很有用的。你可以有服务做其他事情,如身份验证,日志记录等。

services are mainly a way to communicate between controllers, but you can inject one service into another. services are often used as a way to get to your data stores and people will wrap the angular api's such as ngResource. This technique is useful since it makes testing (particularly mocking) quite easy. You can have services for doing other things like authentication, logging etc.

指令用于创建部件或包装存在的事物像jQuery插件。包装现有的插件可以是一个挑战,你可以这样做的原因是要建立一个双向数据的插件和角之间的结合。如果你不需要双向数据绑定,然后你不需要包装它们。

directives are used for creating widgets or wrapping existing things like jquery plugins. Wrapping existing plugins can be a challenge and the reason you would do this is to establish a two-way data binding between the plugins and angular. If you don't need two-way data binding then you don't need to wrap them.

指令也做DOM​​操作,捕获DOM事件等。你不应该在控制器或服务做DOM相关的东西的地方。创建指令可以得到pretty复杂,恕我直言,我建议先寻找API的东西,会做你正在寻找这样做或要求的角度googlegroup的意见是什么。

directives are also a place to do DOM manipulation, catching DOM-events etc. You should not be doing DOM-related stuff in controllers or services. creating directives can get pretty complex, IMHO, I recommend first looking to api for something that will do what you are looking to do OR ask angular googlegroup for advice.

希望这有助于!

- 丹

更多推荐

服务,指导和模块之间的区别

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

发布评论

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

>www.elefans.com

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