[英]Typing in exact URL to visit specific partial Angular using ui-router
Pretty new to Angular, I am sure I'm missing something obvious here. 对Angular来说很新,我相信我在这里遗漏了一些明显的东西。 I am using ui-router. 我正在使用ui-router。
I want to provide a link to my clients so that they can click the URL link and visit the web app with the appropriate partial. 我想提供一个指向我的客户的链接,以便他们可以点击URL链接并访问具有相应部分的Web应用程序。 I also want to be able to pass in parameters. 我也希望能够传递参数。 Here's how I approached this (kind of hokey). 这就是我接近这个问题的方式(有点像)。 This is in my main controller: 这是我的主控制器:
var pNumber = $location.search().number;
if (!(pNumber == null || pNumber == "")){
$state.go('view-ticket');
}
Here is my app.js: 这是我的app.js:
$stateProvider
.state('home', {
url: "/",
templateUrl: 'partials/welcome-screen.html',
controller: 'mainPageController'
})
.state('submit-ticket', {
url: "/submit-ticket",
templateUrl: 'partials/ticket-submit.html',
controller: 'TicketSystemTestCtrl'
})
.state('view-ticket', {
url: "/view",
templateUrl: "partials/ticket-central.html",
controller: 'TicketCentralCtrl'
})
The logic is this: If the URL contains a param 'number' inject ticket-central.html partial. 逻辑是这样的:如果URL包含一个param'number'注入ticket-central.html partial。
However, when I run this in the debugger, it seems the first part of the code got executed before it loads the welcome-screen.html partial. 但是,当我在调试器中运行它时,似乎代码的第一部分在加载welcome-screen.html partial之前已执行。 How to solve this? 怎么解决这个?
EDIT: I am trying to type this into the URL: http://localhost/techsupport/view and I want it to load the ticket-central.html partial into the main view. 编辑:我试图在URL中键入: http:// localhost / techsupport / view ,我希望它将ticket-central.html partial加载到主视图中。 However, it won't work. 但是,它不会起作用。
if i understand correctly all you want to do is to provide a possibility to 'deep-link' to the 'view-ticket' state. 如果我理解正确你想要做的就是提供“深度链接”到“查看票证”状态的可能性。
for this search params are not the ideal solution as they are optional, just use path variables: 对于此搜索,params不是理想的解决方案,因为它们是可选的,只需使用路径变量:
.state('view-ticket', {
url: '/view/:ticketNumber,
template: 'partials/ticket-central.html',
controler: 'TicketCentralCtrl'
})
also don't use the $location service if you don't really have to, have a look at $stateParams 如果你真的不需要,也不要使用$ location服务,看看$ stateParams
here is a small plunkr with a welcome and a ticket state launch the preview in a separate window to see how the url changes - you can also refresh on each page and the correct state will be loaded 这是一个带有欢迎和票证状态的小型plunkr在单独的窗口中启动预览以查看URL如何更改 - 您还可以在每个页面上刷新并且将加载正确的状态
https://plnkr.co/edit/r3UcYbfwET0OVwkd77Rv https://plnkr.co/edit/r3UcYbfwET0OVwkd77Rv
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.