javascript - 从 Angular.js 中的 URL 获取路由参数

标签 javascript angularjs angularjs-routing

如何从以下 URL 获取 ng-controlleraccess_token 的值作为 $routeParams

http://www.example.com/#/access_token=asdfjaksjdhflanblasdfkjahdloahds

最佳答案

在您的应用程序配置上

App.config(['$routeProvider', function($routeProvider) {
  $routeProvider.
  when('/:id', {
    ....
    controller: 'DetailsController'
  }).

在 Controller 上使用$routeParams

.controller("DetailsController", ['$routeParams',function($routeParams){    
    var id = $routeParams.id; // this name is from config :id
}]);

关于javascript - 从 Angular.js 中的 URL 获取路由参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26100931/

相关文章:

events - AngularJS:如何在 promise 完成后防止事件的默认()?

javascript - 不执行 routeprovider 的 Angular 更改 url

angularjs - angularjs中的多个查询字符串参数

c# - 打印页面并关闭

java - JavaScript 对象和 OO/UML/Java 对象有什么区别?

javascript - eventRender 未被触发 Fullcalendar ASP.net C# webforms

javascript - setTimeout() 在忽略间隔的情况下重复调用函数

javascript - 显示无效登录等警报消息的 Angular 方式是什么?

javascript - 将 Web Api 返回日期时间转换为 Javascript 日期

javascript - AngularJS 指令 : How do I hide the alert using timeout?