问题描述
我建立一个Chrome封装应用与AngularJS,它似乎非常可取但使用$ routeProvider似乎是方法不里面的应用程序的URL系统相匹配。
I'm building a Chrome Packaged App with AngularJS and it seems highly desirable to use the $routeProvider however the methods don't seem to match the URL system inside apps.
所以我的问题是,我可以实现Chrome封装应用程序内,如果是这样$ routeProvider功能怎么样?
So my question is can I implement $routeProvider functionality inside a Chrome packaged app and if so how?
推荐答案
不知道这是最好的解决办法,但我似乎已经解决了这个谜我自己。
Not sure if this is the best solution but I seemed to have solved this enigma myself.
设置但是$ routeProvider你希望它是和而不是在应用程序中使用使用链接NG单击使用的$位置更改为任何与您的$ routeProvider路径相匹配的路径指示。
Setup the $routeProvider however you want it to be and instead of using links in the application use ng-click directives that use a the $location to change the path to whatever matches up with your $routeProvider paths.
在下面我做了一个链接指令,设置$ location.path到任何点击,当它等于例子。
in the example below I made a "link" directive that sets the $location.path to whatever it equals when clicked.
#coffescript:
app.directive "link", ($location) ->
(scope, element, attrs) ->
element.bind "click", ->
scope.$apply $location.path(attrs.link)
app.config ($routeProvider) ->
$routeProvider
.when "",
templateUrl: "index.html"
.when "/otherPage",
templateUrl: "path/to/otherPage.html"
.otherwise
template: "Fail!"
空字符串匹配的路由应用的初始状态。
The empty string route matches the initial state of the app.
无论链接attr为连接到将成为一个可点击的链接。
whatever the link attr is attached to will become a clickable link.
<button link="otherPage">Take me to otherPage</button>
<div link="otherPage">Make divs clickable too why not?</div>
这篇关于采用了棱角分明$ routeProvider与打包应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!