2016-11-18 106 views
0

我使用Ionic來建立應用程序。我有一個問題,我不知道如何解決。我想將用戶重定向到另一個選項卡。我讀了關於state.go(),但這些可能不會在這裏工作。它不在控制器中。用戶收到通知後需要重定向到另一個選項卡,然後單擊「顯示」。這是我的代碼。你可以幫我嗎?Ionic/AngularJS - 沒有控制器的state.go

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"); 
 
     } 
 
    ); 
 

 
    }); 
 
})

+0

你的意思是「新標籤」在你的問題中。這是一個新的頁面? – Sravan

+0

對不起,我沒有澄清。據exsiting標籤: '.STATE( 'zglos',{ URL: '/ zglos', templateUrl: '模板/製表zglos.html', 控制器: 'ZglosCtrl' });' –

+0

可以使用'$ state.go'('zglos')'即使在'run block' – Sravan

回答

1

你甚至可以在run block使用ui-router$state

只需添加依賴項$state作爲run block的依賴關係。

.run(function($ionicPlatform, $ionicPopup, $state) { 

    // code goes here 

    $state.go('zglos') 
} 
+0

我很笨。 。我嘗試了一些,但用$ stateProvider。不知道爲什麼。現在它工作。謝謝! –

+0

沒有提及,有一個美好的一天:) – Sravan

+0

如果我想發送這樣的參數: '$ state.go(' zglos',{「newsId」:myId});' 它是正確的嗎?不適合我。 '.STATE( 'zglos',{ 網址: '/ zglos /:NewSID的', templateUrl: '模板/製表zglos.html', 控制器: 'ZglosCtrl' })' –