mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-01-20 01:22:52 +08:00
Merge pull request #201 from driftyco/wip-ng1
feat(angular1): Support Angular 1
This commit is contained in:
commit
46a656fcbc
@ -1,5 +1,4 @@
|
||||
import {initAngular1} from './ng1';
|
||||
initAngular1();
|
||||
|
||||
const DEVICE_READY_TIMEOUT = 2000;
|
||||
|
||||
@ -188,6 +187,8 @@ window['IonicNative'] = {
|
||||
WebIntent: WebIntent
|
||||
};
|
||||
|
||||
initAngular1(window['IonicNative']);
|
||||
|
||||
// To help developers using cordova, we listen for the device ready event and
|
||||
// log an error if it didn't fire in a reasonable amount of time. Generally,
|
||||
// when this happens, developers should remove and reinstall plugins, since
|
||||
|
38
src/ng1.ts
38
src/ng1.ts
@ -1,24 +1,28 @@
|
||||
declare var window;
|
||||
|
||||
/**
|
||||
* Initialize the ngCordova Angular module if we're running in ng1
|
||||
* Initialize the ngCordova 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: $cordovStatusBar.
|
||||
*/
|
||||
export function initAngular1() {
|
||||
export function initAngular1(plugins) {
|
||||
if (window.angular) {
|
||||
window.angular.module('ngCordova', []);
|
||||
window.angular.module('ionic.native', []);
|
||||
|
||||
for(var name in plugins) {
|
||||
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;
|
||||
}])
|
||||
})(serviceName, cls, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish a new Angular 1 service for this plugin.
|
||||
*/
|
||||
export function publishAngular1Service(config: any, cls: any) {
|
||||
let serviceName = '$cordova' + cls.name;
|
||||
console.log('Registering Angular1 service', serviceName);
|
||||
window.angular.module('ngCordova').service(serviceName, [function() {
|
||||
let funcs = {};
|
||||
for (var k in cls) {
|
||||
}
|
||||
return funcs;
|
||||
}]);
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
import {get} from '../util';
|
||||
|
||||
import {publishAngular1Service} from '../ng1';
|
||||
|
||||
declare var window;
|
||||
declare var Promise;
|
||||
declare var $q;
|
||||
|
Loading…
Reference in New Issue
Block a user