简体   繁体   English

如何访问ui路由器的UrlMatcher?

[英]How can i access ui-router's UrlMatcher?

In the documentation of ui-router there is a object named UrlMatcher which i need to access it in order to use some methods (such as exec ) but i cannot find any clear instructions on how to do it. ui-router的文档中,有一个名为UrlMatcher的对象,为了使用某些方法(例如exec ),我需要对其进行访问,但是我找不到有关如何执行此操作的明确说明。 However that object is described on the documentation page. 但是,该对象在文档页面上进行了描述。

I want to be able to do something like: 我希望能够执行以下操作:

new UrlMatcher('/user/{id}?q&r').exec('/user/bob', {
  x: '1', q: 'hello'
});

How can i access that object? 如何访问该对象?

urlMatcherFactory.js on Github Github上的urlMatcherFactory.js

Angular has $urlMatcherFactory and UrlMatchers . Angular有$ urlMatcherFactory和UrlMatchers

Plunker: http://plnkr.co/edit/MdazdvpVKjZhNjI6ErAH?p=preview 柱塞: http ://plnkr.co/edit/MdazdvpVKjZhNjI6ErAH?p=preview

angular.module('myApp',[]).run(['$urlMatcherFactory',
    function($urlMatcherFactory) {

      var sourceList= ['John', 'Paul', 'George', 'Ringo']
      var names = sourceList.join('|');
      var urlMatcher = $urlMatcherFactory.compile("/{source:(?:" + names + ")}/:id");

      $stateProviderRef 
        .state('names', { 
          url: urlMatcher,
          templateUrl: 'tpl.root.html',
          controller: 'MyCtrl'
        });
    }
  ]);

Refer: Discussion on ui-router's UrlMatcher . 请参阅: 关于ui-router的UrlMatcher的讨论

Using exec: 使用exec:

URL: /home/1?param1=tt 网址: / home / 1?param1 = tt

 var urlMatcher = $urlMatcherFactory.compile("/home/:id?param1");
    var matched = urlMatcher.exec($location.path(), $location.search());

you get 2 fields : id ==> 1 and param1 ==> tt 您将获得2个fieldsid ==> 1param1 ==> tt

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使ui-router控制器正常工作? - How can I make ui-router controller to work? Ui-router加载状态,那么我该如何运行一个函数呢? - Ui-router loads state, then how can I run a function? 如何在ng-repeat中将项目路由到angularjs UI-Router中的其他URL,需要在ui-router中修改状态 - How can I route to different URLS in angularjs UI-Router for items in ng-repeat, Need to modify state in ui-router 在使用ui-router的angularjs中,当请求在状态的可解析部分中失败时,如何在$ stateChangeError中访问ngResource错误? - In angularjs using ui-router, how can I access the ngResource error within $stateChangeError when a request fails in the resolve part of a state? 如何访问ui-router $ transitions中的先前状态? - How to access previous state in ui-router $transitions? Angular ui-router:如何防止访问状态 - Angular ui-router: how to prevent access to a state UI-Router的resolve函数参数如何解析? - How are UI-Router's resolve function arguments resolved? 如何将服务注入AngularJS的UI-Router templateUrl函数? - How to inject a service into AngularJS's UI-Router templateUrl function? 我如何编写ui路由器解析,以解决其中一部分返回true或promise的问题? - How can I code a ui-router resolve if part of it will either return true or a promise? Angular UI-Router Minification Error - 如何将Resolve语法更改为基于字符串注入? - Angular UI-Router Minification Error - How Can I Change Resolve Syntax To Be String Injection Based?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM