I’m trying to use ionic-push-notification feature. I am carefully following the push from Scratch tutorial that you can find here: http://docs.ionic.io/docs/push-from-scratch
I always get the same error: Ionic is not defined, when I’m implementing this piece of code to register to the Push:
`.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
var push = new Ionic.Push({
“debug”: true
});
Make sure that you also have cordova.js in your index.html and ngCordova provider in your app.js. Also you need to test on a real device or emulator, not the browser because it will trigger a 404 error for cordova.js file.
I have had already included the dependency of ngCordova in the app.js and running the code on the emulator but it shows the refrenceerror with the module in push.js.
I have the above lists and the module is used in the line 220 only, and the only place where the error is being thrown.
module.exports = {
/**
* Register for Push Notifications.
*
* This method will instantiate a new copy of the PushNotification object
* and start the registration process.
*
* @param {Object} options
* @return {PushNotification} instance
*/
init: function(options) {
return new PushNotification(options);
},
hasPermission: function(successCallback, errorCallback) {
exec(successCallback, errorCallback, 'PushNotification', 'hasPermission', []);
},
/**
* PushNotification Object.
*
* Expose the PushNotification object for direct use
* and testing. Typically, you should use the
* .init helper method.
*/
PushNotification: PushNotification
// angular.module is a global place for creating, registering and retrieving Angular modules
// ‘starter’ is the name of this angular module example (also set in a attribute in index.html)
// the 2nd parameter is an array of 'requires’
angular.module(‘starter’, [‘ionic’,‘ngCordova’])
push.on(‘error’, function(e) {
alert(e.message);
});
if(window.cordova && window.cordova.plugins.Keyboard) {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
// Don't remove this line unless you know what you are doing. It stops the viewport
// from snapping when text inputs are focused. Ionic handles this internally for
// a much nicer keyboard experience.
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
sad but it still doesnt work. I did the above the plugin appears in package but it still shows the module missing. I am sorry to have wasted your time.
{
“name”: “unhappy”,
“version”: “1.1.1”,
“description”: “UnHappy: An Ionic project”,
“dependencies”: {
“gulp”: “^3.5.6”,
“gulp-sass”: “^2.0.4”,
“gulp-concat”: “^2.2.0”,
“gulp-minify-css”: “^0.3.0”,
“gulp-rename”: “^1.2.0”
},
“devDependencies”: {
“bower”: “^1.3.3”,
“gulp-util”: “^2.2.14”,
“shelljs”: “^0.3.0”
},
“cordovaPlugins”: [
“cordova-plugin-device”,
“cordova-plugin-console”,
“cordova-plugin-whitelist”,
“cordova-plugin-splashscreen”,
“cordova-plugin-statusbar”,
“ionic-plugin-keyboard”,
“phonegap-plugin-push”
],
“cordovaPlatforms”: [
“android”
]
}
I don’t know i tried with a fresh project and still no avail, the plugins doesn’t get like that in my package.json. Maybe i am having error on gitpart. Anyway thankyou so much for your effort and help. You helped a lot to a noob stranger. I may come in handy at certain times. You can add me at rumba.alex47@gmail.com. Thankyou so much for your help.
No worries, One last thing to check, are you sure that your push.js file is included right after cordova.js in your index.html template? You can also use my package.json and do ionic state reset and see if you have any luck.
I just want device taken rest i will be doing on .net. And, i have tried ngCordova which has problem with the event call back and the ionic.io which is having problem with the ionic not being defined. hahahhahaha. Neway, thankyou once again for being of so much help.