Skip to content

Commit

Permalink
feat(angular1): Support Angular 1
Browse files Browse the repository at this point in the history
  • Loading branch information
mlynch committed Jun 9, 2016
1 parent aec9570 commit af8fbde
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {initAngular1} from './ng1';
initAngular1();

const DEVICE_READY_TIMEOUT = 2000;

Expand Down Expand Up @@ -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
Expand Down
36 changes: 20 additions & 16 deletions src/ng1.ts
Original file line number Diff line number Diff line change
@@ -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', []);

/**
* 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) {
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);
}
return funcs;
}]);
}
}
2 changes: 0 additions & 2 deletions src/plugins/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {get} from '../util';

import {publishAngular1Service} from '../ng1';

declare var window;
declare var Promise;
declare var $q;
Expand Down

0 comments on commit af8fbde

Please sign in to comment.