@angular-wave/angular.ts 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -0
- package/.eslintrc.cjs +29 -0
- package/.github/workflows/playwright.yml +27 -0
- package/CHANGELOG.md +17974 -0
- package/CODE_OF_CONDUCT.md +3 -0
- package/CONTRIBUTING.md +246 -0
- package/DEVELOPERS.md +488 -0
- package/LICENSE +22 -0
- package/Makefile +31 -0
- package/README.md +115 -0
- package/RELEASE.md +98 -0
- package/SECURITY.md +16 -0
- package/TRIAGING.md +135 -0
- package/css/angular.css +22 -0
- package/dist/angular-ts.cjs.js +36843 -0
- package/dist/angular-ts.esm.js +36841 -0
- package/dist/angular-ts.umd.js +36848 -0
- package/dist/build/angular-animate.js +4272 -0
- package/dist/build/angular-aria.js +426 -0
- package/dist/build/angular-message-format.js +1072 -0
- package/dist/build/angular-messages.js +829 -0
- package/dist/build/angular-mocks.js +3757 -0
- package/dist/build/angular-parse-ext.js +1275 -0
- package/dist/build/angular-resource.js +911 -0
- package/dist/build/angular-route.js +1266 -0
- package/dist/build/angular-sanitize.js +891 -0
- package/dist/build/angular-touch.js +368 -0
- package/dist/build/angular.js +36600 -0
- package/e2e/unit.spec.ts +15 -0
- package/images/android-chrome-192x192.png +0 -0
- package/images/android-chrome-512x512.png +0 -0
- package/images/apple-touch-icon.png +0 -0
- package/images/favicon-16x16.png +0 -0
- package/images/favicon-32x32.png +0 -0
- package/images/favicon.ico +0 -0
- package/images/site.webmanifest +1 -0
- package/index.html +104 -0
- package/package.json +47 -0
- package/playwright.config.ts +78 -0
- package/public/circle.html +1 -0
- package/public/my_child_directive.html +1 -0
- package/public/my_directive.html +1 -0
- package/public/my_other_directive.html +1 -0
- package/public/test.html +1 -0
- package/rollup.config.js +31 -0
- package/src/animations/animateCache.js +55 -0
- package/src/animations/animateChildrenDirective.js +105 -0
- package/src/animations/animateCss.js +1139 -0
- package/src/animations/animateCssDriver.js +291 -0
- package/src/animations/animateJs.js +367 -0
- package/src/animations/animateJsDriver.js +67 -0
- package/src/animations/animateQueue.js +851 -0
- package/src/animations/animation.js +506 -0
- package/src/animations/module.js +779 -0
- package/src/animations/ngAnimateSwap.js +119 -0
- package/src/animations/rafScheduler.js +50 -0
- package/src/animations/shared.js +378 -0
- package/src/constants.js +20 -0
- package/src/core/animate.js +845 -0
- package/src/core/animateCss.js +73 -0
- package/src/core/animateRunner.js +195 -0
- package/src/core/attributes.js +199 -0
- package/src/core/cache.js +45 -0
- package/src/core/compile.js +4727 -0
- package/src/core/controller.js +225 -0
- package/src/core/exceptionHandler.js +63 -0
- package/src/core/filter.js +146 -0
- package/src/core/interpolate.js +442 -0
- package/src/core/interval.js +188 -0
- package/src/core/intervalFactory.js +57 -0
- package/src/core/location.js +1086 -0
- package/src/core/parser/parse.js +2562 -0
- package/src/core/parser/parse.md +13 -0
- package/src/core/q.js +746 -0
- package/src/core/rootScope.js +1596 -0
- package/src/core/sanitizeUri.js +85 -0
- package/src/core/sce.js +1161 -0
- package/src/core/taskTrackerFactory.js +125 -0
- package/src/core/timeout.js +121 -0
- package/src/core/urlUtils.js +187 -0
- package/src/core/utils.js +1349 -0
- package/src/directive/a.js +37 -0
- package/src/directive/attrs.js +283 -0
- package/src/directive/bind.js +51 -0
- package/src/directive/bind.md +142 -0
- package/src/directive/change.js +12 -0
- package/src/directive/change.md +25 -0
- package/src/directive/cloak.js +12 -0
- package/src/directive/cloak.md +24 -0
- package/src/directive/events.js +75 -0
- package/src/directive/events.md +166 -0
- package/src/directive/form.js +725 -0
- package/src/directive/init.js +15 -0
- package/src/directive/init.md +41 -0
- package/src/directive/input.js +1783 -0
- package/src/directive/list.js +46 -0
- package/src/directive/list.md +22 -0
- package/src/directive/ngClass.js +249 -0
- package/src/directive/ngController.js +64 -0
- package/src/directive/ngCsp.js +82 -0
- package/src/directive/ngIf.js +134 -0
- package/src/directive/ngInclude.js +217 -0
- package/src/directive/ngModel.js +1356 -0
- package/src/directive/ngModelOptions.js +509 -0
- package/src/directive/ngOptions.js +670 -0
- package/src/directive/ngRef.js +90 -0
- package/src/directive/ngRepeat.js +650 -0
- package/src/directive/ngShowHide.js +255 -0
- package/src/directive/ngSwitch.js +178 -0
- package/src/directive/ngTransclude.js +98 -0
- package/src/directive/non-bindable.js +11 -0
- package/src/directive/non-bindable.md +17 -0
- package/src/directive/script.js +30 -0
- package/src/directive/select.js +624 -0
- package/src/directive/style.js +25 -0
- package/src/directive/style.md +23 -0
- package/src/directive/validators.js +329 -0
- package/src/exts/aria.js +544 -0
- package/src/exts/messages.js +852 -0
- package/src/filters/filter.js +207 -0
- package/src/filters/filter.md +69 -0
- package/src/filters/filters.js +239 -0
- package/src/filters/json.md +16 -0
- package/src/filters/limit-to.js +43 -0
- package/src/filters/limit-to.md +19 -0
- package/src/filters/order-by.js +183 -0
- package/src/filters/order-by.md +83 -0
- package/src/index.js +13 -0
- package/src/injector.js +1034 -0
- package/src/jqLite.js +1117 -0
- package/src/loader.js +1320 -0
- package/src/public.js +215 -0
- package/src/routeToRegExp.js +41 -0
- package/src/services/anchorScroll.js +135 -0
- package/src/services/browser.js +321 -0
- package/src/services/cacheFactory.js +398 -0
- package/src/services/cookieReader.js +72 -0
- package/src/services/document.js +64 -0
- package/src/services/http.js +1537 -0
- package/src/services/httpBackend.js +206 -0
- package/src/services/log.js +160 -0
- package/src/services/templateRequest.js +139 -0
- package/test/angular.spec.js +2153 -0
- package/test/aria/aria.spec.js +1245 -0
- package/test/binding.spec.js +504 -0
- package/test/build-test.html +14 -0
- package/test/injector.spec.js +2327 -0
- package/test/jasmine/jasmine-5.1.2/boot0.js +65 -0
- package/test/jasmine/jasmine-5.1.2/boot1.js +133 -0
- package/test/jasmine/jasmine-5.1.2/jasmine-html.js +963 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.css +320 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.js +10824 -0
- package/test/jasmine/jasmine-5.1.2/jasmine_favicon.png +0 -0
- package/test/jasmine/jasmine-browser.json +17 -0
- package/test/jasmine/jasmine.json +9 -0
- package/test/jqlite.spec.js +2133 -0
- package/test/loader.spec.js +219 -0
- package/test/messages/messages.spec.js +1146 -0
- package/test/min-err.spec.js +174 -0
- package/test/mock-test.html +13 -0
- package/test/module-test.html +15 -0
- package/test/ng/anomate.spec.js +606 -0
- package/test/ng/cache-factor.spec.js +334 -0
- package/test/ng/compile.spec.js +17956 -0
- package/test/ng/controller-provider.spec.js +227 -0
- package/test/ng/cookie-reader.spec.js +98 -0
- package/test/ng/directive/a.spec.js +192 -0
- package/test/ng/directive/bind.spec.js +334 -0
- package/test/ng/directive/boolean.spec.js +136 -0
- package/test/ng/directive/change.spec.js +71 -0
- package/test/ng/directive/class.spec.js +858 -0
- package/test/ng/directive/click.spec.js +38 -0
- package/test/ng/directive/cloak.spec.js +44 -0
- package/test/ng/directive/constoller.spec.js +194 -0
- package/test/ng/directive/element-style.spec.js +92 -0
- package/test/ng/directive/event.spec.js +282 -0
- package/test/ng/directive/form.spec.js +1518 -0
- package/test/ng/directive/href.spec.js +143 -0
- package/test/ng/directive/if.spec.js +402 -0
- package/test/ng/directive/include.spec.js +828 -0
- package/test/ng/directive/init.spec.js +68 -0
- package/test/ng/directive/input.spec.js +3810 -0
- package/test/ng/directive/list.spec.js +170 -0
- package/test/ng/directive/model-options.spec.js +1008 -0
- package/test/ng/directive/model.spec.js +1905 -0
- package/test/ng/directive/non-bindable.spec.js +55 -0
- package/test/ng/directive/options.spec.js +3583 -0
- package/test/ng/directive/ref.spec.js +575 -0
- package/test/ng/directive/repeat.spec.js +1675 -0
- package/test/ng/directive/script.spec.js +52 -0
- package/test/ng/directive/scrset.spec.js +67 -0
- package/test/ng/directive/select.spec.js +2541 -0
- package/test/ng/directive/show-hide.spec.js +253 -0
- package/test/ng/directive/src.spec.js +157 -0
- package/test/ng/directive/style.spec.js +178 -0
- package/test/ng/directive/switch.spec.js +647 -0
- package/test/ng/directive/validators.spec.js +717 -0
- package/test/ng/document.spec.js +52 -0
- package/test/ng/filter/filter.spec.js +714 -0
- package/test/ng/filter/filters.spec.js +35 -0
- package/test/ng/filter/limit-to.spec.js +251 -0
- package/test/ng/filter/order-by.spec.js +891 -0
- package/test/ng/filter.spec.js +149 -0
- package/test/ng/http-backend.spec.js +398 -0
- package/test/ng/http.spec.js +4071 -0
- package/test/ng/interpolate.spec.js +642 -0
- package/test/ng/interval.spec.js +343 -0
- package/test/ng/location.spec.js +3488 -0
- package/test/ng/on.spec.js +229 -0
- package/test/ng/parse.spec.js +4655 -0
- package/test/ng/prop.spec.js +805 -0
- package/test/ng/q.spec.js +2904 -0
- package/test/ng/root-element.spec.js +16 -0
- package/test/ng/sanitize-uri.spec.js +249 -0
- package/test/ng/sce.spec.js +660 -0
- package/test/ng/scope.spec.js +3442 -0
- package/test/ng/template-request.spec.js +236 -0
- package/test/ng/timeout.spec.js +351 -0
- package/test/ng/url-utils.spec.js +156 -0
- package/test/ng/utils.spec.js +144 -0
- package/test/original-test.html +21 -0
- package/test/public.spec.js +34 -0
- package/test/sanitize/bing-html.spec.js +36 -0
- package/test/server/express.js +158 -0
- package/test/test-utils.js +11 -0
- package/tsconfig.json +17 -0
- package/types/angular.d.ts +138 -0
- package/types/global.d.ts +9 -0
- package/types/index.d.ts +2357 -0
- package/types/jqlite.d.ts +558 -0
- package/vite.config.js +14 -0
|
@@ -0,0 +1,575 @@
|
|
|
1
|
+
import { createInjector } from "../../../src/injector";
|
|
2
|
+
import { publishExternalAPI } from "../../../src/public";
|
|
3
|
+
|
|
4
|
+
describe("ngRef", () => {
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
jasmine.addMatchers({
|
|
7
|
+
toEqualJq(util) {
|
|
8
|
+
return {
|
|
9
|
+
compare(actual, expected) {
|
|
10
|
+
// Jquery <= 2.2 objects add a context property that is irrelevant for equality
|
|
11
|
+
if (actual && actual.hasOwnProperty("context")) {
|
|
12
|
+
delete actual.context;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (expected && expected.hasOwnProperty("context")) {
|
|
16
|
+
delete expected.context;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
pass: util.equals(actual, expected),
|
|
21
|
+
};
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("on a component", () => {
|
|
29
|
+
let myComponentController;
|
|
30
|
+
let attributeDirectiveController;
|
|
31
|
+
let $rootScope;
|
|
32
|
+
let $compile;
|
|
33
|
+
let injector;
|
|
34
|
+
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
publishExternalAPI().decorator("$exceptionHandler", function () {
|
|
37
|
+
return (exception, cause) => {
|
|
38
|
+
throw new Error(exception.message);
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
injector = createInjector([
|
|
42
|
+
"ng",
|
|
43
|
+
($compileProvider) => {
|
|
44
|
+
$compileProvider.component("myComponent", {
|
|
45
|
+
template: "foo",
|
|
46
|
+
controller() {
|
|
47
|
+
myComponentController = this;
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
$compileProvider.directive("attributeDirective", () => ({
|
|
52
|
+
restrict: "A",
|
|
53
|
+
controller() {
|
|
54
|
+
attributeDirectiveController = this;
|
|
55
|
+
},
|
|
56
|
+
}));
|
|
57
|
+
},
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
$compile = injector.get("$compile");
|
|
61
|
+
$rootScope = injector.get("$rootScope");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should bind in the current scope the controller of a component", () => {
|
|
65
|
+
$rootScope.$ctrl = "undamaged";
|
|
66
|
+
$compile('<my-component ng-ref="myComponentRef"></my-component>')(
|
|
67
|
+
$rootScope,
|
|
68
|
+
);
|
|
69
|
+
expect($rootScope.$ctrl).toBe("undamaged");
|
|
70
|
+
//expect($rootScope.myComponentRef).toBe(myComponentController);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// it("should throw if the expression is not assignable", () => {
|
|
74
|
+
// expect(() => {
|
|
75
|
+
// $compile("<my-component ng-ref=\"'hello'\"></my-component>")(
|
|
76
|
+
// $rootScope,
|
|
77
|
+
// );
|
|
78
|
+
// }).toThrow(
|
|
79
|
+
// "ngRef",
|
|
80
|
+
// "nonassign",
|
|
81
|
+
// "Expression in ngRef=\"'hello'\" is non-assignable!",
|
|
82
|
+
// );
|
|
83
|
+
// });
|
|
84
|
+
|
|
85
|
+
// it("should work with non:normalized entity name", () => {
|
|
86
|
+
// $compile('<my:component ng-ref="myComponent1"></my:component>')(
|
|
87
|
+
// $rootScope,
|
|
88
|
+
// );
|
|
89
|
+
// expect($rootScope.myComponent1).toBe(myComponentController);
|
|
90
|
+
// });
|
|
91
|
+
|
|
92
|
+
// it("should work with data-non-normalized entity name", () => {
|
|
93
|
+
// $compile('<data-my-component ng-ref="myComponent2"></data-my-component>')(
|
|
94
|
+
// $rootScope,
|
|
95
|
+
// );
|
|
96
|
+
// expect($rootScope.myComponent2).toBe(myComponentController);
|
|
97
|
+
// });
|
|
98
|
+
|
|
99
|
+
// it("should work with x-non-normalized entity name", () => {
|
|
100
|
+
// $compile('<x-my-component ng-ref="myComponent3"></x-my-component>')(
|
|
101
|
+
// $rootScope,
|
|
102
|
+
// );
|
|
103
|
+
// expect($rootScope.myComponent3).toBe(myComponentController);
|
|
104
|
+
// });
|
|
105
|
+
|
|
106
|
+
// it("should work with data-non-normalized attribute name", () => {
|
|
107
|
+
// $compile('<my-component data-ng-ref="myComponent1"></my-component>')(
|
|
108
|
+
// $rootScope,
|
|
109
|
+
// );
|
|
110
|
+
// expect($rootScope.myComponent1).toBe(myComponentController);
|
|
111
|
+
// });
|
|
112
|
+
|
|
113
|
+
// it("should work with x-non-normalized attribute name", () => {
|
|
114
|
+
// $compile('<my-component x-ng-ref="myComponent2"></my-component>')(
|
|
115
|
+
// $rootScope,
|
|
116
|
+
// );
|
|
117
|
+
// expect($rootScope.myComponent2).toBe(myComponentController);
|
|
118
|
+
// });
|
|
119
|
+
|
|
120
|
+
// it("should not bind the controller of an attribute directive", () => {
|
|
121
|
+
// $compile(
|
|
122
|
+
// '<my-component attribute-directive-1 ng-ref="myComponentRef"></my-component>',
|
|
123
|
+
// )($rootScope);
|
|
124
|
+
// expect($rootScope.myComponentRef).toBe(myComponentController);
|
|
125
|
+
// });
|
|
126
|
+
|
|
127
|
+
// it("should not leak to parent scopes", () => {
|
|
128
|
+
// const template =
|
|
129
|
+
// '<div ng-if="true">' +
|
|
130
|
+
// '<my-component ng-ref="myComponent"></my-component>' +
|
|
131
|
+
// "</div>";
|
|
132
|
+
// $compile(template)($rootScope);
|
|
133
|
+
// expect($rootScope.myComponent).toBe(undefined);
|
|
134
|
+
// });
|
|
135
|
+
|
|
136
|
+
// it("should nullify the variable once the component is destroyed", () => {
|
|
137
|
+
// const template =
|
|
138
|
+
// '<div><my-component ng-ref="myComponent"></my-component></div>';
|
|
139
|
+
|
|
140
|
+
// const element = $compile(template)($rootScope);
|
|
141
|
+
// expect($rootScope.myComponent).toBe(myComponentController);
|
|
142
|
+
|
|
143
|
+
// const componentElement = element.children();
|
|
144
|
+
// const isolateScope = componentElement.isolateScope();
|
|
145
|
+
// componentElement.remove();
|
|
146
|
+
// isolateScope.$destroy();
|
|
147
|
+
// expect($rootScope.myComponent).toBe(null);
|
|
148
|
+
// });
|
|
149
|
+
|
|
150
|
+
// it("should be compatible with entering/leaving components", () => {
|
|
151
|
+
// const template = '<my-component ng-ref="myComponent"></my-component>';
|
|
152
|
+
// $rootScope.$ctrl = {};
|
|
153
|
+
// const parent = $compile("<div></div>")($rootScope);
|
|
154
|
+
|
|
155
|
+
// const leaving = $compile(template)($rootScope);
|
|
156
|
+
// const leavingController = myComponentController;
|
|
157
|
+
|
|
158
|
+
// $animate.enter(leaving, parent);
|
|
159
|
+
// expect($rootScope.myComponent).toBe(leavingController);
|
|
160
|
+
|
|
161
|
+
// const entering = $compile(template)($rootScope);
|
|
162
|
+
// const enteringController = myComponentController;
|
|
163
|
+
|
|
164
|
+
// $animate.enter(entering, parent);
|
|
165
|
+
// $animate.leave(leaving, parent);
|
|
166
|
+
// expect($rootScope.myComponent).toBe(enteringController);
|
|
167
|
+
// });
|
|
168
|
+
|
|
169
|
+
// it("should allow binding to a nested property", () => {
|
|
170
|
+
// $rootScope.obj = {};
|
|
171
|
+
|
|
172
|
+
// $compile('<my-component ng-ref="obj.myComponent"></my-component>')(
|
|
173
|
+
// $rootScope,
|
|
174
|
+
// );
|
|
175
|
+
// expect($rootScope.obj.myComponent).toBe(myComponentController);
|
|
176
|
+
// });
|
|
177
|
+
// });
|
|
178
|
+
|
|
179
|
+
// it("should bind the jqlite wrapped DOM element if there is no component", inject((
|
|
180
|
+
// $compile,
|
|
181
|
+
// $rootScope,
|
|
182
|
+
// ) => {
|
|
183
|
+
// const el = $compile('<span ng-ref="mySpan">my text</span>')($rootScope);
|
|
184
|
+
|
|
185
|
+
// expect($rootScope.mySpan).toEqualJq(el);
|
|
186
|
+
// expect($rootScope.mySpan[0].textContent).toBe("my text");
|
|
187
|
+
// }));
|
|
188
|
+
|
|
189
|
+
// it("should nullify the expression value if the DOM element is destroyed", inject((
|
|
190
|
+
// $compile,
|
|
191
|
+
// $rootScope,
|
|
192
|
+
// ) => {
|
|
193
|
+
// const element = $compile('<div><span ng-ref="mySpan">my text</span></div>')(
|
|
194
|
+
// $rootScope,
|
|
195
|
+
// );
|
|
196
|
+
// element.children().remove();
|
|
197
|
+
// expect($rootScope.mySpan).toBe(null);
|
|
198
|
+
// }));
|
|
199
|
+
|
|
200
|
+
// it("should bind the controller of an element directive", () => {
|
|
201
|
+
// let myDirectiveController;
|
|
202
|
+
|
|
203
|
+
// module(($compileProvider) => {
|
|
204
|
+
// $compileProvider.directive("myDirective", () => ({
|
|
205
|
+
// controller() {
|
|
206
|
+
// myDirectiveController = this;
|
|
207
|
+
// },
|
|
208
|
+
// }));
|
|
209
|
+
// });
|
|
210
|
+
|
|
211
|
+
// inject(($compile, $rootScope) => {
|
|
212
|
+
// $compile('<my-directive ng-ref="myDirective"></my-directive>')(
|
|
213
|
+
// $rootScope,
|
|
214
|
+
// );
|
|
215
|
+
|
|
216
|
+
// expect($rootScope.myDirective).toBe(myDirectiveController);
|
|
217
|
+
// });
|
|
218
|
+
// });
|
|
219
|
+
|
|
220
|
+
// describe("ngRefRead", () => {
|
|
221
|
+
// it('should bind the element instead of the controller of a component if ngRefRead="$element" is set', () => {
|
|
222
|
+
// module(($compileProvider) => {
|
|
223
|
+
// $compileProvider.component("myComponent", {
|
|
224
|
+
// template: "my text",
|
|
225
|
+
// controller() {},
|
|
226
|
+
// });
|
|
227
|
+
// });
|
|
228
|
+
|
|
229
|
+
// inject(($compile, $rootScope) => {
|
|
230
|
+
// const el = $compile(
|
|
231
|
+
// '<my-component ng-ref="myEl" ng-ref-read="$element"></my-component>',
|
|
232
|
+
// )($rootScope);
|
|
233
|
+
// expect($rootScope.myEl).toEqualJq(el);
|
|
234
|
+
// expect($rootScope.myEl[0].textContent).toBe("my text");
|
|
235
|
+
// });
|
|
236
|
+
// });
|
|
237
|
+
|
|
238
|
+
// it('should bind the element instead an element-directive controller if ngRefRead="$element" is set', () => {
|
|
239
|
+
// module(($compileProvider) => {
|
|
240
|
+
// $compileProvider.directive("myDirective", () => ({
|
|
241
|
+
// restrict: "E",
|
|
242
|
+
// template: "my text",
|
|
243
|
+
// controller() {},
|
|
244
|
+
// }));
|
|
245
|
+
// });
|
|
246
|
+
|
|
247
|
+
// inject(($compile, $rootScope) => {
|
|
248
|
+
// const el = $compile(
|
|
249
|
+
// '<my-directive ng-ref="myEl" ng-ref-read="$element"></my-directive>',
|
|
250
|
+
// )($rootScope);
|
|
251
|
+
|
|
252
|
+
// expect($rootScope.myEl).toEqualJq(el);
|
|
253
|
+
// expect($rootScope.myEl[0].textContent).toBe("my text");
|
|
254
|
+
// });
|
|
255
|
+
// });
|
|
256
|
+
|
|
257
|
+
// it('should bind an attribute-directive controller if ngRefRead="controllerName" is set', () => {
|
|
258
|
+
// let attrDirective1Controller;
|
|
259
|
+
|
|
260
|
+
// module(($compileProvider) => {
|
|
261
|
+
// $compileProvider.directive("elementDirective", () => ({
|
|
262
|
+
// restrict: "E",
|
|
263
|
+
// template: "my text",
|
|
264
|
+
// controller() {},
|
|
265
|
+
// }));
|
|
266
|
+
|
|
267
|
+
// $compileProvider.directive("attributeDirective1", () => ({
|
|
268
|
+
// restrict: "A",
|
|
269
|
+
// controller() {
|
|
270
|
+
// attrDirective1Controller = this;
|
|
271
|
+
// },
|
|
272
|
+
// }));
|
|
273
|
+
|
|
274
|
+
// $compileProvider.directive("attributeDirective2", () => ({
|
|
275
|
+
// restrict: "A",
|
|
276
|
+
// controller() {},
|
|
277
|
+
// }));
|
|
278
|
+
// });
|
|
279
|
+
|
|
280
|
+
// inject(($compile, $rootScope) => {
|
|
281
|
+
// const el = $compile(
|
|
282
|
+
// "<element-directive" +
|
|
283
|
+
// "attribute-directive-1" +
|
|
284
|
+
// "attribute-directive-2" +
|
|
285
|
+
// 'ng-ref="myController"' +
|
|
286
|
+
// 'ng-ref-read="$element"></element-directive>',
|
|
287
|
+
// )($rootScope);
|
|
288
|
+
|
|
289
|
+
// expect($rootScope.myController).toBe(attrDirective1Controller);
|
|
290
|
+
// });
|
|
291
|
+
// });
|
|
292
|
+
|
|
293
|
+
// it("should throw if no controller is found for the ngRefRead value", () => {
|
|
294
|
+
// module(($compileProvider) => {
|
|
295
|
+
// $compileProvider.directive("elementDirective", () => ({
|
|
296
|
+
// restrict: "E",
|
|
297
|
+
// template: "my text",
|
|
298
|
+
// controller() {},
|
|
299
|
+
// }));
|
|
300
|
+
// });
|
|
301
|
+
|
|
302
|
+
// inject(($compile, $rootScope) => {
|
|
303
|
+
// expect(() => {
|
|
304
|
+
// $compile(
|
|
305
|
+
// "<element-directive " +
|
|
306
|
+
// 'ng-ref="myController"' +
|
|
307
|
+
// 'ng-ref-read="attribute"></element-directive>',
|
|
308
|
+
// )($rootScope);
|
|
309
|
+
// }).toThrow(
|
|
310
|
+
// "ngRef",
|
|
311
|
+
// "noctrl",
|
|
312
|
+
// 'The controller for ngRefRead="attribute" could not be found on ngRef="myController"',
|
|
313
|
+
// );
|
|
314
|
+
// });
|
|
315
|
+
// });
|
|
316
|
+
// });
|
|
317
|
+
|
|
318
|
+
// it("should bind the jqlite element if the controller is on an attribute-directive", () => {
|
|
319
|
+
// let myDirectiveController;
|
|
320
|
+
|
|
321
|
+
// module(($compileProvider) => {
|
|
322
|
+
// $compileProvider.directive("myDirective", () => ({
|
|
323
|
+
// restrict: "A",
|
|
324
|
+
// template: "my text",
|
|
325
|
+
// controller() {
|
|
326
|
+
// myDirectiveController = this;
|
|
327
|
+
// },
|
|
328
|
+
// }));
|
|
329
|
+
// });
|
|
330
|
+
|
|
331
|
+
// inject(($compile, $rootScope) => {
|
|
332
|
+
// const el = $compile('<div my-directive ng-ref="myEl"></div>')($rootScope);
|
|
333
|
+
|
|
334
|
+
// expect(myDirectiveController).toBeDefined();
|
|
335
|
+
// expect($rootScope.myEl).toEqualJq(el);
|
|
336
|
+
// expect($rootScope.myEl[0].textContent).toBe("my text");
|
|
337
|
+
// });
|
|
338
|
+
// });
|
|
339
|
+
|
|
340
|
+
// it("should bind the jqlite element if the controller is on an class-directive", () => {
|
|
341
|
+
// let myDirectiveController;
|
|
342
|
+
|
|
343
|
+
// module(($compileProvider) => {
|
|
344
|
+
// $compileProvider.directive("myDirective", () => ({
|
|
345
|
+
// restrict: "C",
|
|
346
|
+
// template: "my text",
|
|
347
|
+
// controller() {
|
|
348
|
+
// myDirectiveController = this;
|
|
349
|
+
// },
|
|
350
|
+
// }));
|
|
351
|
+
// });
|
|
352
|
+
|
|
353
|
+
// inject(($compile, $rootScope) => {
|
|
354
|
+
// const el = $compile('<div class="my-directive" ng-ref="myEl"></div>')(
|
|
355
|
+
// $rootScope,
|
|
356
|
+
// );
|
|
357
|
+
|
|
358
|
+
// expect(myDirectiveController).toBeDefined();
|
|
359
|
+
// expect($rootScope.myEl).toEqualJq(el);
|
|
360
|
+
// expect($rootScope.myEl[0].textContent).toBe("my text");
|
|
361
|
+
// });
|
|
362
|
+
// });
|
|
363
|
+
|
|
364
|
+
// describe("transclusion", () => {
|
|
365
|
+
// it("should work with simple transclusion", () => {
|
|
366
|
+
// module(($compileProvider) => {
|
|
367
|
+
// $compileProvider.component("myComponent", {
|
|
368
|
+
// transclude: true,
|
|
369
|
+
// template: "<ng-transclude></ng-transclude>",
|
|
370
|
+
// controller() {
|
|
371
|
+
// this.text = "SUCCESS";
|
|
372
|
+
// },
|
|
373
|
+
// });
|
|
374
|
+
// });
|
|
375
|
+
|
|
376
|
+
// inject(($compile, $rootScope) => {
|
|
377
|
+
// const template =
|
|
378
|
+
// '<my-component ng-ref="myComponent">{{myComponent.text}}</my-component>';
|
|
379
|
+
// const element = $compile(template)($rootScope);
|
|
380
|
+
// $rootScope.$apply();
|
|
381
|
+
// expect(element.text()).toBe("SUCCESS");
|
|
382
|
+
// dealoc(element);
|
|
383
|
+
// });
|
|
384
|
+
// });
|
|
385
|
+
|
|
386
|
+
// it("should be compatible with element transclude components", () => {
|
|
387
|
+
// module(($compileProvider) => {
|
|
388
|
+
// $compileProvider.component("myComponent", {
|
|
389
|
+
// transclude: "element",
|
|
390
|
+
// controller($animate, $element, $transclude) {
|
|
391
|
+
// this.text = "SUCCESS";
|
|
392
|
+
// this.$postLink = function () {
|
|
393
|
+
// $transclude((clone, newScope) => {
|
|
394
|
+
// $animate.enter(clone, $element.parent(), $element);
|
|
395
|
+
// });
|
|
396
|
+
// };
|
|
397
|
+
// },
|
|
398
|
+
// });
|
|
399
|
+
// });
|
|
400
|
+
|
|
401
|
+
// inject(($compile, $rootScope) => {
|
|
402
|
+
// const template =
|
|
403
|
+
// "<div>" +
|
|
404
|
+
// '<my-component ng-ref="myComponent">' +
|
|
405
|
+
// "{{myComponent.text}}" +
|
|
406
|
+
// "</my-component>" +
|
|
407
|
+
// "</div>";
|
|
408
|
+
// const element = $compile(template)($rootScope);
|
|
409
|
+
// $rootScope.$apply();
|
|
410
|
+
// expect(element.text()).toBe("SUCCESS");
|
|
411
|
+
// dealoc(element);
|
|
412
|
+
// });
|
|
413
|
+
// });
|
|
414
|
+
|
|
415
|
+
// it("should be compatible with ngIf and transclusion on same element", () => {
|
|
416
|
+
// module(($compileProvider) => {
|
|
417
|
+
// $compileProvider.component("myComponent", {
|
|
418
|
+
// template: "<ng-transclude></ng-transclude>",
|
|
419
|
+
// transclude: true,
|
|
420
|
+
// controller($scope) {
|
|
421
|
+
// this.text = "SUCCESS";
|
|
422
|
+
// },
|
|
423
|
+
// });
|
|
424
|
+
// });
|
|
425
|
+
|
|
426
|
+
// inject(($compile, $rootScope) => {
|
|
427
|
+
// const template =
|
|
428
|
+
// "<div>" +
|
|
429
|
+
// '<my-component ng-if="present" ng-ref="myComponent" >' +
|
|
430
|
+
// "{{myComponent.text}}" +
|
|
431
|
+
// "</my-component>" +
|
|
432
|
+
// "</div>";
|
|
433
|
+
// const element = $compile(template)($rootScope);
|
|
434
|
+
|
|
435
|
+
// $rootScope.$apply("present = false");
|
|
436
|
+
// expect(element.text()).toBe("");
|
|
437
|
+
// $rootScope.$apply("present = true");
|
|
438
|
+
// expect(element.text()).toBe("SUCCESS");
|
|
439
|
+
// $rootScope.$apply("present = false");
|
|
440
|
+
// expect(element.text()).toBe("");
|
|
441
|
+
// $rootScope.$apply("present = true");
|
|
442
|
+
// expect(element.text()).toBe("SUCCESS");
|
|
443
|
+
// dealoc(element);
|
|
444
|
+
// });
|
|
445
|
+
// });
|
|
446
|
+
|
|
447
|
+
// it("should be compatible with element transclude & destroy components", () => {
|
|
448
|
+
// let myComponentController;
|
|
449
|
+
// module(($compileProvider) => {
|
|
450
|
+
// $compileProvider.component("myTranscludingComponent", {
|
|
451
|
+
// transclude: "element",
|
|
452
|
+
// controller($animate, $element, $transclude) {
|
|
453
|
+
// myComponentController = this;
|
|
454
|
+
|
|
455
|
+
// let currentClone;
|
|
456
|
+
// let currentScope;
|
|
457
|
+
// this.transclude = function (text) {
|
|
458
|
+
// this.text = text;
|
|
459
|
+
// $transclude((clone, newScope) => {
|
|
460
|
+
// currentClone = clone;
|
|
461
|
+
// currentScope = newScope;
|
|
462
|
+
// $animate.enter(clone, $element.parent(), $element);
|
|
463
|
+
// });
|
|
464
|
+
// };
|
|
465
|
+
// this.destroy = function () {
|
|
466
|
+
// currentClone.remove();
|
|
467
|
+
// currentScope.$destroy();
|
|
468
|
+
// };
|
|
469
|
+
// },
|
|
470
|
+
// });
|
|
471
|
+
// });
|
|
472
|
+
|
|
473
|
+
// inject(($compile, $rootScope) => {
|
|
474
|
+
// const template =
|
|
475
|
+
// "<div>" +
|
|
476
|
+
// '<my-transcluding-component ng-ref="myComponent">' +
|
|
477
|
+
// "{{myComponent.text}}" +
|
|
478
|
+
// "</my-transcluding-component>" +
|
|
479
|
+
// "</div>";
|
|
480
|
+
// const element = $compile(template)($rootScope);
|
|
481
|
+
// $rootScope.$apply();
|
|
482
|
+
// expect(element.text()).toBe("");
|
|
483
|
+
|
|
484
|
+
// myComponentController.transclude("transcludedOk");
|
|
485
|
+
// $rootScope.$apply();
|
|
486
|
+
// expect(element.text()).toBe("transcludedOk");
|
|
487
|
+
|
|
488
|
+
// myComponentController.destroy();
|
|
489
|
+
// $rootScope.$apply();
|
|
490
|
+
// expect(element.text()).toBe("");
|
|
491
|
+
// });
|
|
492
|
+
// });
|
|
493
|
+
|
|
494
|
+
// it("should be compatible with element transclude directives", () => {
|
|
495
|
+
// module(($compileProvider) => {
|
|
496
|
+
// $compileProvider.directive("myDirective", ($animate) => ({
|
|
497
|
+
// transclude: "element",
|
|
498
|
+
// controller() {
|
|
499
|
+
// this.text = "SUCCESS";
|
|
500
|
+
// },
|
|
501
|
+
// link(scope, element, attrs, ctrl, $transclude) {
|
|
502
|
+
// $transclude((clone, newScope) => {
|
|
503
|
+
// $animate.enter(clone, element.parent(), element);
|
|
504
|
+
// });
|
|
505
|
+
// },
|
|
506
|
+
// }));
|
|
507
|
+
// });
|
|
508
|
+
|
|
509
|
+
// inject(($compile, $rootScope) => {
|
|
510
|
+
// const template =
|
|
511
|
+
// "<div>" +
|
|
512
|
+
// '<my-directive ng-ref="myDirective">' +
|
|
513
|
+
// "{{myDirective.text}}" +
|
|
514
|
+
// "</my-directive>" +
|
|
515
|
+
// "</div>";
|
|
516
|
+
// const element = $compile(template)($rootScope);
|
|
517
|
+
// $rootScope.$apply();
|
|
518
|
+
// expect(element.text()).toBe("SUCCESS");
|
|
519
|
+
// dealoc(element);
|
|
520
|
+
// });
|
|
521
|
+
// });
|
|
522
|
+
// });
|
|
523
|
+
|
|
524
|
+
// it("should work with components with templates via $http", () => {
|
|
525
|
+
// module(($compileProvider) => {
|
|
526
|
+
// $compileProvider.component("httpComponent", {
|
|
527
|
+
// templateUrl: "template.html",
|
|
528
|
+
// controller() {
|
|
529
|
+
// this.me = true;
|
|
530
|
+
// },
|
|
531
|
+
// });
|
|
532
|
+
// });
|
|
533
|
+
|
|
534
|
+
// inject(($compile, $httpBackend, $rootScope) => {
|
|
535
|
+
// const template =
|
|
536
|
+
// '<div><http-component ng-ref="controller"></http-component></div>';
|
|
537
|
+
// const element = $compile(template)($rootScope);
|
|
538
|
+
// $httpBackend.expect("GET", "template.html").respond("ok");
|
|
539
|
+
// $rootScope.$apply();
|
|
540
|
+
// expect($rootScope.controller).toBeUndefined();
|
|
541
|
+
// $httpBackend.flush();
|
|
542
|
+
// expect($rootScope.controller.me).toBe(true);
|
|
543
|
+
// dealoc(element);
|
|
544
|
+
// });
|
|
545
|
+
// });
|
|
546
|
+
|
|
547
|
+
// it("should work with ngRepeat-ed components", () => {
|
|
548
|
+
// const controllers = [];
|
|
549
|
+
|
|
550
|
+
// module(($compileProvider) => {
|
|
551
|
+
// $compileProvider.component("myComponent", {
|
|
552
|
+
// template: "foo",
|
|
553
|
+
// controller() {
|
|
554
|
+
// controllers.push(this);
|
|
555
|
+
// },
|
|
556
|
+
// });
|
|
557
|
+
// });
|
|
558
|
+
|
|
559
|
+
// inject(($compile, $rootScope) => {
|
|
560
|
+
// $rootScope.elements = [0, 1, 2, 3, 4];
|
|
561
|
+
// $rootScope.controllers = []; // Initialize the array because ngRepeat creates a child scope
|
|
562
|
+
|
|
563
|
+
// const template =
|
|
564
|
+
// '<div><my-component ng-repeat="(key, el) in elements" ng-ref="controllers[key]"></my-component></div>';
|
|
565
|
+
// const element = $compile(template)($rootScope);
|
|
566
|
+
// $rootScope.$apply();
|
|
567
|
+
|
|
568
|
+
// expect($rootScope.controllers).toEqual(controllers);
|
|
569
|
+
|
|
570
|
+
// $rootScope.$apply("elements = []");
|
|
571
|
+
|
|
572
|
+
// expect($rootScope.controllers).toEqual([null, null, null, null, null]);
|
|
573
|
+
// });
|
|
574
|
+
});
|
|
575
|
+
});
|