[英]Ionic/AngularJS - state.go without controller
I use Ionic for builing apps. 我使用Ionic构建应用程序。 I have one problem that I don't know how to solve.
我有一个我不知道如何解决的问题。 I want to redirect user to another tab.
我想将用户重定向到另一个选项卡。 I read about state.go() but these probably won't work here.
我读到有关state.go()的信息,但这些可能在这里不起作用。 It's not in controller.
它不在控制器中。 User needs to be redirect to another tab after he receive notification and clicks "Show".
用户收到通知并单击“显示”后,需要将其重定向到另一个选项卡。 This is my code.
这是我的代码。 Can you help me?
你能帮助我吗?
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services']) .run(function($ionicPlatform, $ionicPopup) { $ionicPlatform.ready(function() { if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) { cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); cordova.plugins.Keyboard.disableScroll(true); } if (window.StatusBar) { StatusBar.styleDefault(); } FCMPlugin.getToken( function(token){ console.log("Użytkownik zarejestrowany"); }, function(err){ console.log('Nie udało się połączyć z usługą powiadamiania'); } ) FCMPlugin.onNotification( function(data){ if (data.wasTapped){ // I need that code here } else { var confirmPopup = $ionicPopup.confirm({ title: "Notification", template: 'Want to read?', cancelText: 'I want to read', okText: 'Nope' }); confirmPopup.then(function(res) { if (res) { // I need that code here } }); } }, function(msg){ console.log("Ok"); }, function(err){ console.log("Error"); } ); }); })
You can use the $state
of ui-router
even in run block
. 您甚至可以在
run block
使用ui-router
的$state
。
Just add the dependency $state
as the dependency of run block
. 只需添加依赖项
$state
作为run block
的依赖项即可。
.run(function($ionicPlatform, $ionicPopup, $state) {
// code goes here
$state.go('zglos')
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.