2017-06-01 27 views
0

这是我的网址:

http://localhost:8091/apps/dashboard/#!/#%2Findex%3Fsession=564badc5919b42fa880f1b34ae5d0740 

从下面提到的代码我收到 '未定义':

$location.search().session 

什么是错在这里?我是Angular的新成员,想从查询字符串中获取会话变量。

在此先感谢!

回答

0

想象我的URL构造不正确。重新构建的网址,并开始按预期工作。

对我来说,这是正确的URL格式:

http://localhost:8091/apps/SPMDashboardApp/#!/index?session==564badc5919b42fa880f1b34ae5d0740 
0

它需要包括$ locationProvider在你的app.config。 然后,您需要在使用$ location.search()之前配置html5Mode。 以下示例将帮助您。

app.config(['$routeProvider', '$locationProvider', function($routeProvider, 
$locationProvider) { 
    $routeProvider 
     .when("/", { 
      templateUrl : 'xxx.html' 
      , controller: 'xxxController' 
     }); 

    $locationProvider.html5Mode({ 
     enabled: true, 
     requireBase: false 
    }); 

干杯!