AngularJS笔记1
来源:互联网 发布:如何查看网站seo 编辑:程序博客网 时间:2024/05/16 13:53
Do not use controllers to:
- Manipulate DOM — Controllers should contain only business logic. Putting any presentation logic into Controllers significantly affects its testability. Angular has databinding for most cases and directives to encapsulate manual DOM manipulation.
- Format input — Use angular form controls instead.
- Filter output — Use angular filters instead.
- Share code or state across controllers — Use angular services instead.
- Manage the life-cycle of other components (for example, to create service instances).
Let's write some tests to show how to override configuration in tests.
describe('myApp', function() { // load application module (`greetMod`) then load a special // test module which overrides `$window` with a mock version, // so that calling `window.alert()` will not block the test // runner with a real alert box. beforeEach(module('greetMod', function($provide) { $provide.value('$window', { alert: jasmine.createSpy('alert') }); })); // inject() will create the injector and inject the `greet` and // `$window` into the tests. it('should alert on $window', inject(function(greet, $window) { greet('World'); expect($window.alert).toHaveBeenCalledWith('Hello World!'); })); // this is another way of overriding configuration in the // tests using inline `module` and `inject` methods. it('should alert using the alert service', function() { var alertSpy = jasmine.createSpy('alert'); module(function($provide) { $provide.value('alert', alertSpy); }); inject(function(greet) { greet('World'); expect(alertSpy).toHaveBeenCalledWith('Hello World!'); }); });});
0 0
- AngularJS笔记1
- angularJS 学习笔记1
- AngularJS 学习笔记1
- AngularJS学习笔记1
- angularjs 学习笔记1
- AngularJS学习笔记1
- **AngularJs学习笔记1**
- AngularJs自学笔记(1)
- AngularJS学习笔记(1)
- AngularJS学习笔记(1)
- AngularJS-学习笔记(1)
- AngularJS入门笔记(1)
- angularjs学习笔记(1)
- AngularJS学习笔记(1)
- AngularJS笔记
- AngularJS 笔记
- angularjs笔记
- AngularJS笔记
- Valid Palindrome
- Windows的日期、时间函数的例子
- 【cocos2dx 3.2】Flappy Bird开发超详细讲解(二)素材准备和屏幕自适应分辨率
- C99标准的新特性
- BZOJ系列1090《[SCOI2003]字符串折叠》题解
- AngularJS笔记1
- nfl jerseys china nike
- BFS思想
- 安卓5.0系统
- Vertica转换Local时间到GMT时间
- Random
- 记录填加后取出id
- 早晨的阳光
- .NET开发者必备的11款免费工具