Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49107

"Uncaught TypeError: Cannot read property 'on' of undefined"

$
0
0

@derekrada wrote:

I have a fairly generic app that I am trying to test ionic push with but when I run in the code on an android emulator I am getting an error as shown in the title regarding on of undefined. The on is a reference to an EventEmitter attached to the this value so it could very well be scoping issue. I followed the instructions on ionic however this is the error I keep getting. When I ran this in test mode where dev_push true, it worked while doing ionic serve. However it does not work on my current setup even though I followed the directions to a tee. If anyone has any input I will gladly provide more information but hopefully I just missed something simple.

Plugins:

ionic plugin list
cordova-plugin-device 1.1.1 "Device"
cordova-plugin-geolocation 2.1.0 "Geolocation"
cordova-plugin-whitelist 1.2.1 "Whitelist"
phonegap-plugin-push 1.6.1 "PushPlugin"

CordovaPlugins in package.json:

"cordovaPlugins": [
"cordova-plugin-device",
"cordova-plugin-console",
"cordova-plugin-whitelist",
"cordova-plugin-splashscreen",
"cordova-plugin-statusbar",
"ionic-plugin-keyboard",
"cordova-plugin-geolocation",
{
"variables": {
"SENDER_ID": "MY_SENDER_ID"
},
"locator": "phonegap-plugin-push",
"id": "phonegap-plugin-push"
}
],

error:

04-03 06:12:02.880 3248-3248/com.ionicframework.MYAPPI/chromium: [INFO:CONSOLE(26)] "Starting ionicPush", source: file:///android_asset/www/js/app.js (26)
04-03 06:12:02.880 3248-3248/com.ionicframework.MYAPPI/chromium: [INFO:CONSOLE(2)] "Ionic Push:", source: file:///android_asset/www/lib/ionic-platform-web-client/dist/ionic.io.bundle.min.js (2)
04-03 06:12:02.880 3248-3248/com.ionicframework.MYAPPI/chromium: [INFO:CONSOLE(2)] "Ionic Push:", source: file:///android_asset/www/lib/ionic-platform-web-client/dist/ionic.io.bundle.min.js (2)
04-03 06:12:02.880 3248-3248/com.ionicframework.MYAPPI/chromium: [INFO:CONSOLE(3)] "Uncaught TypeError: Cannot read property 'on' of undefined", source: file:///android_asset/www/lib/ionic-platform-web-client/dist/ionic.io.bundle.min.js (3)

That line of code (from the ionic-platform-web-client):

/**
* Fire a callback when Push is ready. This will fire immediately if
* the service has already initialized.
*
* @param {function} callback Callback function to fire off
* @return {void}
*/
}, {
key: "onReady",
value: function onReady(callback) {
var self = this;
if (this._isReady) {
callback(self);
} else {
self.emitter.on('ionicpush:ready', function () {
callback(self);
});
}
}
}

My code:

$ionicPlatform.ready(function() {

console.log('Starting ionicPush');
push = new Ionic.Push();

push.register(function(data) {
   token = data.token;
   console.log("Got Token:", data.token);
});
...

My index.html

<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/ionic-platform-web-client/dist/ionic.io.bundle.min.js"></script>

<script src="lib/ngCordova/dist/ng-cordova.js"></script>

<script src="js/app.js"></script>

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 49107

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>