Merge pull request #201 from driftyco/wip-ng1

feat(angular1): Support Angular 1
This commit is contained in:
Ibrahim Hadeed 2016-06-09 12:38:47 -04:00
commit 46a656fcbc
3 changed files with 23 additions and 20 deletions

View File

@ -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

View File

@ -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() {
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);
}
}
}

View File

@ -1,7 +1,5 @@
import {get} from '../util';
import {publishAngular1Service} from '../ng1';
declare var window;
declare var Promise;
declare var $q;