28 lines
828 B
TypeScript
Raw Normal View History

2017-12-28 07:28:44 -05:00
declare const window: any;
/**
* Initialize the ionic.native Angular module if we're running in ng1.
* This iterates through the list of registered plugins and dynamically
* creates Angular 1 services of the form $cordovaSERVICE, ex: $cordovaStatusBar.
*/
export function initAngular1(plugins: any) {
2019-02-23 16:54:09 -06:00
if (typeof window !== 'undefined' && window.angular) {
2017-12-28 07:28:44 -05:00
const ngModule = window.angular.module('ionic.native', []);
for (const name in plugins) {
2018-03-23 10:42:10 +01:00
const serviceName = '$cordova' + name;
const cls = plugins[name];
2017-12-28 07:28:44 -05:00
2018-09-17 18:23:18 +02:00
((serviceName, cls, name) => {
ngModule.service(serviceName, [
2018-09-17 18:23:18 +02:00
() => {
const funcs = window.angular.copy(cls);
funcs.__proto__['name'] = name;
return funcs;
}
]);
2017-12-28 07:28:44 -05:00
})(serviceName, cls, name);
}
}
}