28 lines
809 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: $cordovStatusBar.
2015-12-01 13:33:08 -06:00
*/
2016-06-09 11:24:38 -05:00
export function initAngular1(plugins) {
if (window.angular) {
2016-06-09 11:24:38 -05:00
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) {
window.angular.module('ionic.native').service(serviceName, [function() {
let funcs = {};
for (var k in cls) {
funcs[k] = cls[k];
}
funcs['name'] = name;
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
}
2016-06-09 21:22:05 -04:00
}