Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 发送到应用程序中通知时的状态单击ionic中的OneSignal插件_Javascript_Angularjs_Ionic Framework_Ngcordova_Onesignal - Fatal编程技术网

Javascript 发送到应用程序中通知时的状态单击ionic中的OneSignal插件

Javascript 发送到应用程序中通知时的状态单击ionic中的OneSignal插件,javascript,angularjs,ionic-framework,ngcordova,onesignal,Javascript,Angularjs,Ionic Framework,Ngcordova,Onesignal,这是我的配置文件 (function () { 'use strict'; angular .module('app.core') .config(['$ionicConfigProvider', '$httpProvider', '$compileProvider', function ($ionicConfigProvider, $httpProvider, $compileProvider) { $ionicConfigProvider.t

这是我的配置文件

(function () {
    'use strict';
    angular
    .module('app.core')
    .config(['$ionicConfigProvider', '$httpProvider', '$compileProvider', function ($ionicConfigProvider, $httpProvider, $compileProvider) {

        $ionicConfigProvider.tabs.position('bottom'); // other values: top
        $compileProvider.debugInfoEnabled(false); // remove while debugging

        $httpProvider.interceptors.push('authInterceptorService');
        document.addEventListener('deviceready', function ($state) {

            var notificationOpenedCallback = function (jsonData) {
                console.log('didReceiveRemoteNotificationCallBack: ' + JSON.stringify(jsonData));
            };
            window.plugins.OneSignal.init("xxxxx-xxxxxx-xxxxxx-xxxx",
            { googleProjectNumber: "xxxxxxxxx" },
            notificationOpenedCallback);


            window.plugins.OneSignal.getIds(function (ids) {
                var deviceId = ids;
                console.log(deviceId);
                localStorage.setItem('deviceId', deviceId.userId);
            });

            // Show an alert box if a notification comes in when the user is in your app.
            window.plugins.OneSignal.enableInAppAlertNotification(true);
        }, false);

    }]);

})();
通知OpenedCallback发生在点击堆积在设备选项卡上的推送消息时。因此,我想转到一个特定的路由,而不仅仅是打开应用程序,它现在正在这样做。 在notificationOpenedCallback函数中,我希望能够路由到特定的状态,如

 .state('tabs.answered', {
        url: "/answered",
        views: {
            'tab-answered': {
                templateUrl: "app/answeredfeed/answered.html",
                controller: 'AnsweredCtrl',
                controllerAs: 'vm'
            }
        },
        authRequired: true
    });
通常我会做一个

$state.go('tabs.answered');

但问题是我无法注入$state或$stateprovider,以便可以路由到tabs.answered。甚至有可能从配置路由,还是我都搞错了?这个功能可以通过其他方式实现吗?

将angular.config更改为angular.run,我可以注入$injector 因此可以做一个

var state = $injector.get($state);
state.go('desiredstate');

将angular.config更改为angular.run,我可以注入$injector 因此可以做一个

var state = $injector.get($state);
state.go('desiredstate');