AngularUI $ StateParams多个参数未定义

时间:2022-02-12 11:21:11

Simply trying to get the token sent back to me in URL. New to AngularUI so not understanding why.

只需尝试通过URL将令牌发回给我。 AngularUI的新手,所以不明白为什么。

Here is the route:

这是路线:

angular.module('myApp')
  .config(function($stateProvider) {
    $stateProvider
      .state('oauth_callback', {
        url: '/oauth_callback?access_token&expires_in',
        templateUrl: 'app/oauth_callback/oauth_callback.html',
        controller: 'OauthCallbackCtrl'
      });
  });

Here is all i'm doing for the controller:

以下是我为控制器所做的一切:

ngular.module('myApp')
  .controller('OauthCallbackCtrl', function ($scope, $stateParams) {
  	console.log('## params:', $stateParams);
  });

The console log returns:

控制台日志返回:

## params: Object {access_token: undefined, expires_in: undefined}

Any help would be appreciated. Thanks.

任何帮助,将不胜感激。谢谢。

1 个解决方案

#1


1  

I've was into a similar issue when I was developing one app that uses oAuth, with ui-router.

当我开发一个使用oAuth和ui-router的应用程序时,我遇到了类似的问题。

My problem was a bit different, because some internal redirections that I do, to setup a i18n routing. When the oAuth was redirecting me back to my app, it was going crazy, because of the hash that it applies and the ui-router structure that I've developed.

我的问题有点不同,因为我做了一些内部重定向,设置了i18n路由。当oAuth将我重定向回我的应用程序时,由于它应用的散列和我开发的ui-router结构,它变得很疯狂。

I've ended up setting up the redirect URL on oAuth pointing to a neutral HTML page, that parses the hash, stores it on localStorage, and then I close the window.

我最终在oAuth上设置了指向中性HTML页面的重定向URL,它解析了哈希,将其存储在localStorage上,然后我关闭了窗口。

When the user call the authentication, I trigger a new window/tab opening, with the oAuth server. On my angular app, I activate one $interval that looks for the existence and validity of the localStorage key defined by me. While its not filled up by that HTML, it keeps looking for it. When it gets it, I proceed with the things on the app.

当用户调用身份验证时,我会使用oAuth服务器触发新的窗口/选项卡打开。在我的角度应用程序中,我激活一个$ interval,查找我定义的localStorage键的存在性和有效性。虽然它没有填充HTML,但它一直在寻找它。当它得到它,我继续在应用程序上的东西。

#1


1  

I've was into a similar issue when I was developing one app that uses oAuth, with ui-router.

当我开发一个使用oAuth和ui-router的应用程序时,我遇到了类似的问题。

My problem was a bit different, because some internal redirections that I do, to setup a i18n routing. When the oAuth was redirecting me back to my app, it was going crazy, because of the hash that it applies and the ui-router structure that I've developed.

我的问题有点不同,因为我做了一些内部重定向,设置了i18n路由。当oAuth将我重定向回我的应用程序时,由于它应用的散列和我开发的ui-router结构,它变得很疯狂。

I've ended up setting up the redirect URL on oAuth pointing to a neutral HTML page, that parses the hash, stores it on localStorage, and then I close the window.

我最终在oAuth上设置了指向中性HTML页面的重定向URL,它解析了哈希,将其存储在localStorage上,然后我关闭了窗口。

When the user call the authentication, I trigger a new window/tab opening, with the oAuth server. On my angular app, I activate one $interval that looks for the existence and validity of the localStorage key defined by me. While its not filled up by that HTML, it keeps looking for it. When it gets it, I proceed with the things on the app.

当用户调用身份验证时,我会使用oAuth服务器触发新的窗口/选项卡打开。在我的角度应用程序中,我激活一个$ interval,查找我定义的localStorage键的存在性和有效性。虽然它没有填充HTML,但它一直在寻找它。当它得到它,我继续在应用程序上的东西。