2
schangxiang@126.com
2024-08-16 b47c50a2a514def7374b32d7194b2c599cba5625
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var testModule = angular.module('testModule', []);
 
// config blocks
testModule.config(function() {
  spy.config('config1');
});
 
testModule.config(function() {
  spy.config('config2');
});
 
// run blocks
testModule.run(function() {
  spy.run('run1');
});
 
testModule.run(function() {
  spy.run('run2');
});
 
// controllers
testModule.controller('TestCtrl', function($scope) {
  spy.ctrl('ctrl');
});
 
// services
testModule.factory('testService', [function () {
  spy.service('service');
  return {};
}]);
 
// filters
angular.module('testModule').filter('testFilter', function () {
  spy.filter('filter');
  return function (input) {
    return input;
  }
});
 
// directives
testModule.directive("test", function () {
  spy.directive('directive');
  return {
    restrict: 'E',
    replace: true,
    template: '<div>Test template {{1 + 1}}</div>'
  };
});
 
if(angular.version.minor > 3) { // only in angular 1.4+
    // decorators
    testModule.decorator("testService", function($delegate) {
        spy.decorator('decorator');
        return $delegate;
    });
}
 
// redefine directive to check that both won't be invoked (it would throw a [$compile:multidir] Multiple directives)
testModule.directive("test", function () {
  spy.directive('directive');
  return {
    restrict: 'E',
    replace: true,
    template: '<div>Test template {{1 + 1}}</div>'
  };
});
 
// constants
testModule.constant("myConst0", {bar: 'foo'});
testModule.constant("myConst1", "something");
testModule.constant("myConst2", undefined);
testModule.constant("myConst3", null);
testModule.constant("myConst4", function() {});