27 lines
758 B
TypeScript
Raw Normal View History

2015-12-01 13:33:08 -06:00
declare var window;
/**
2016-06-09 21:22:05 -04:00
* Initialize the ionic.native Angular module if we're running in ng1.
2016-06-09 11:24:38 -05:00
* This iterates through the list of registered plugins and dynamically
* creates Angular 1 services of the form $cordovaSERVICE, ex: $cordovaStatusBar.
2015-12-01 13:33:08 -06:00
*/
2016-06-09 11:24:38 -05:00
export function initAngular1(plugins) {
if (window.angular) {
2016-09-07 02:42:29 +01:00
const ngModule = window.angular.module('ionic.native', []);
2015-12-01 13:33:08 -06:00
2016-06-09 21:22:05 -04:00
for (var name in plugins) {
2016-06-09 11:24:38 -05:00
let serviceName = '$cordova' + name;
let cls = plugins[name];
(function(serviceName, cls, name) {
2016-09-07 02:42:29 +01:00
ngModule.service(serviceName, [function() {
var funcs = window.angular.copy(cls);
funcs.prototype['name'] = name;
2016-06-09 11:24:38 -05:00
return funcs;
2016-06-09 21:20:55 -04:00
}]);
2016-06-09 11:24:38 -05:00
})(serviceName, cls, name);
2015-12-01 13:33:08 -06:00
}
2016-06-09 11:24:38 -05:00
}
}