Service and controller in angularJs
Separation of concern is at the heart while designing an AngularJS application. Your controller must be responsible for binding model data to views using $scope. It does not contain logic to fetch the data or manipulating it.
For that we must create singleton objects called services. AngularJS can manage these service objects. Wherever we want to use the service, we just have to specify its name and AngularJS auto-magically inject these objects (more on this later).
Thus service is a stateless object that contains some useful functions. These functions can be called from anywhere; Controllers, Directive, Filters etc. Thus we can divide our application in logical units. The business logic or logic to call HTTP url to fetch data from server can be put within a service object.
Putting business and other logic within services has many advantages. First it fulfills the principle of separation of concern or segregation of duties. Each component is responsible for its own work making application more manageable. Second this way each component can be more testable. AngularJS provides first class support for unit testing. Thus we can quickly write tests for our services making them robust and less error prone.
And I must say that reference [1] is really a good article!
Reference
[1]http://viralpatel.net/blogs/angularjs-service-factory-tutorial/
Service and controller in angularJs的更多相关文章
- @Repository、@Service、@Controller 和 @Component
转载:http://blog.csdn.net/ye1992/article/details/19971467 spring 自 2.0 版本开始,陆续引入了一些注解用于简化 Spring 的开发.@ ...
- Spring注解@Component、@Repository、@Service、@Controller区别 .
Spring 2.5 中除了提供 @Component 注释外,还定义了几个拥有特殊语义的注释,它们分别是:@Repository.@Service 和 @Controller.在目前的 Spring ...
- [转] Spring注解@Component、@Repository、@Service、@Controller区别
原文地址:http://blog.csdn.net/zhang854429783/article/details/6785574 很长时间没做web项目都把以前学的那点框架知识忘光了,今天把以前做的一 ...
- @Repository、@Service、@Controller 和 @Component(转)
鸣谢:http://blog.csdn.net/ye1992/article/details/19971467 @Repository.@Service.@Controller 和 @Componen ...
- Spring注解@Component、@Repository、@Service、@Controller,@Autowired、@Resource用法
一.Spring定义bean,@Component.@Repository.@Service 和 @Controller Spring 2.5 中除了提供 @Component 注释外,还定义了几个拥 ...
- 【转】Spring注解@Component、@Repository、@Service、@Controller区别
http://blog.csdn.net/zhang854429783/article/details/6785574 很长时间没做web项目都把以前学的那点框架知识忘光了,今天把以前做的一个项目翻出 ...
- Spring中用@Component、@Repository、@Service和 @Controller等标注的默认Bean名称会是小写开头的非限定类名
今天用调度平台去调用bean中的方法时,提示找不到bean.经查,发现是由于如果在标注上没有提供name属性值,则默认的bean名称是小写开头的,而不是大写开头的. 下面是其他文档参阅: 使用过滤器自 ...
- Spring学习使用标签来标记资源(@Component、@Repository、 @Service和@Controller)和用法(包括如何jsp正在使用)
首先,在xml其中新增部分标有下划线的文件,容器初始化的时候需要扫描包 注意: a. 包款扫描(下划线部分)一定要加,默认是不扫描整个包.与每一包之间','开.如过具有同样的父包,那么我们能够 ...
- SpringMVC注解@Component、@Repository、@Service、@Controller区别
SpringMVC中四个基本注解: @Component.@Repository @Service.@Controller 看字面含义,很容易却别出其中三个: @Controller 控制层, ...
随机推荐
- (转载)android:android.content.res.Resources$NotFoundException: String resource ID #..
android.content.res.Resources$NotFoundException: String resource ID #0x0 找不到资源文件ID #0x0 原因分析如下: 遇到这种 ...
- iOS面试题
一个区分度很大的面试题 考察一个面试者基础咋样,基本上问一个 @property 就够了: @property 后面可以有哪些修饰符? 线程安全的: atomic,nonatomic 访问权限的 re ...
- REDHAT一总复习1 输出重定向及head tail的用法
1.使用bash命令,在server机上完成以下任务.(考点是:head tail的使用) .显示/usr/bin/clean-binary-files文件的前12行,并将其输出到/home/stu ...
- 思考JavaScript异常如何转为知识库?
线上 js 报错会变成一个邮件,发给前端开发 team,每个人自己认领.解决.其实这是一个不错的选择,也解决了最基本的问题:立即响应,修掉.不过也存在着一个问题,如何避免同样的错误?我的初步想法是这样 ...
- secureCRT The remote system refused the connection.
转 http://blog.csdn.net/lifengxun20121019/article/details/13627757 我在实践远程登录工具SecureCRT的时候遇到了这个问题 Ubun ...
- 项目vue2.0仿外卖APP(三)
项目的结构如下: 项目资源准备 准备项目的各种图片资源等等 注意:在webpack可以不用css sprite,直接用单张图片,因为它会帮忙打包. 还有SVG图片, ...
- string类型转换int类型
C++转换形式(C++11): int main(int argc, char* argv[]) { std::"; std::string str2 = "3.14159&quo ...
- grep
http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2856896.html
- Django(4)html模板继承、模板导入、分页实现
1.获取所有请求信息 导入模块:from django.core.handlers.wsgi import WSGIRequest request.environ:包含所有的请求信息,可以打印看一下, ...
- django(3) 一对多跨表查询、ajax、多对多
1.一对多跨表查询获取数据的三种形式:对象.字典.元组 例:有host与business两张表,host与business的id字段关联,business在host表中的对象名是b, 通过查询hos ...