我正在制作一个资源查看器应用程序,但问题是我试图匹配 when("/!/:resourceUrl").
如果资源网址类似/path,它可以正常工作,但我怎样才能做出类似的东西/path/to/the/resource.
我不知道需要多少路径,所以我不能这样做.when("/!/:path1/:path2/:path3").
有任何想法吗?
我想创建一个角度站点来处理用户可以在文件系统树中导航的文件,(例如在github : github.com/angular/angular.js/tree/master/path/to/my/file.js.
我想path/to/my/file.js用角度路线捕获URL的那一部分:
.when("/files/:myPath", templateUrl: "...", controller: "...")
Run Code Online (Sandbox Code Playgroud)
但正如预期的那样,:myPath只匹配下一个斜线.
如何捕获URL的所有剩余部分,包括任意数量的斜杠?
我发现这个问题是相关的,但不同之处在于我的URL在角度哈希之后很好,例如.../index.html#/files/path/to/my/file.
我正在尝试$location.path从AngularJS指令中更新.它没有按照我的预期工作,即更新浏览器窗口中显示的URL并在我的页面上显示不同的内容.我的函数肯定会被调用正确的值,如控制台中所示.我认为$location.path可能会产生一些影响,因为当我点击链接时,会调用一些在新页面上调用的附加函数,只会显示新页面.当我$location.path在控制器中使用时,它按预期工作,但不在我的指令中.
这是我的指令的HTML:
<div detail-link="/comments?post={{post.postId}}" ng-click="clickDetailLink()"></div>
Run Code Online (Sandbox Code Playgroud)
这是指令的定义(在CoffeeScript中):
directives.directive 'detailLink', ['$location', ($location) ->
return (scope, element, attrs) ->
scope.clickDetailLink = ->
console.log "loading " + scope.detailLinkHref
$location.path scope.detailLinkHref
attrs.$observe 'detailLink', (value) ->
console.log "set detail link to " + value
scope.detailLinkHref = value
]
Run Code Online (Sandbox Code Playgroud)
我知道这里发生了什么......我$routeProvider已经设置好处理/comments但是在这里我试图将一个查询字符串附加到路由中.如果我使用常规<a href="#/comments?post={{post.postId}}">,这工作正常,但以某种方式设置相同的路线通过$location.path是行不通的.这与代码是否在控制器或指令中无关.