javascript 未捕获的 ReferenceError:未为 Ionic Push 定义 Ionic
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33893100/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Uncaught ReferenceError: Ionic is not defined for Ionic Push
提问by MZH
I'm trying to add Ionic.io Push to my application but its throwing Ionic is not defined
我正在尝试将 Ionic.io Push 添加到我的应用程序中,但未定义其抛出的 Ionic
ReferenceError: Ionic is not defined
var push = new Ionic.Push({
Everything is working fine except this undefined error, I've run this command to update lib but nothing happen, bundle version is * Ionic, v1.1.0
除了这个未定义的错误,一切都正常,我已经运行这个命令来更新 lib 但什么也没发生,包版本是 * Ionic, v1.1.0
ionic lib update
My app.js
我的 app.js
angular.module('TestApp', ['ionic','ionic.service.core',
'ionic.service.push',
'lavoApp.controllers',
'lavoApp.services','ngCordova'])
.run(function($ionicPlatform,$rootScope,$location,$timeout,$anchorScroll,$state,$ionicHistory,$cordovaPush) {
$ionicPlatform.ready(function() {
var push = new Ionic.Push({
"debug": true
});
push.register(function(token) {
console.log("Device token:",token.token);
});
回答by Deepika
Just add below line after
只需在下面添加以下行
<script src="lib/ionic/ionic.bundle.js"></script>
in your index.htmlfile.
在您的index.html文件中。
<script src="lib/ionic-platform-web-client/dist/ionic.io.bundle.js"></script>
回答by Amir Kadi?
This error occurs before you run ionic io init
. It's also necessary to run ionic config set dev_push true
right after that if you're running the app in a browser (otherwise you'll get "PushNotification is not defined"). The whole push notification setup procedure is described here.
在您运行之前会发生此错误ionic io init
。ionic config set dev_push true
如果您在浏览器中运行该应用程序,还必须在此之后立即运行(否则您将收到“未定义 PushNotification”)。此处描述了整个推送通知设置过程 。
回答by Sensei James
In following the setup steps, Ionic CLI autowrote to my index.html:
按照设置步骤,Ionic CLI 自动写入我的 index.html:
<script src="lib/ionic-platform-web-client/dist/ionic.io.bundle.min.js"></script>
but I had to manually retrieve the source file (ionic.io.bundle.min.js) from:
但我必须从以下位置手动检索源文件(ionic.io.bundle.min.js):
and put it in the expected directory:
并将其放在预期的目录中:
lib/ionic-platform-web-client/dist/
I also had to disable and then re-enable limited pushes from the CLI:
我还必须从 CLI 禁用然后重新启用有限的推送:
ionic config set dev_push true
Nothing else worked for me. Good luck!
没有其他东西对我有用。祝你好运!
回答by Sunil Lama
Ionic.io(); was supposed to be overruled in the latest version. However, adding Ionic.io(); before var push =Ionic.Push() solved the problem for me. i.e, after i had added the ionic-platform-web-client and push-plugin.
离子.io(); 应该在最新版本中被否决。但是,添加 Ionic.io(); 在 var push =Ionic.Push() 为我解决问题之前。即,在我添加了 ionic-platform-web-client 和 push-plugin 之后。
回答by Brandon M
This is a general dependency problem! This means somehow your Ionic dependency from bower is not installed correctly. Try to run "bower install" to install all the dependencies again.
这是一个普遍的依赖问题!这意味着不知何故您对 bower 的 Ionic 依赖没有正确安装。尝试运行“bower install”以再次安装所有依赖项。
回答by ricardoweb
You have to verify your ionic-cli version. It has to be the latest, or at least 1.7.10. check enter link description here
您必须验证您的 ionic-cli 版本。它必须是最新的,或者至少是 1.7.10。检查在此处输入链接描述