[英]creating routes using Angular JS
Im starting with Angular JS and trying to do this project I have, however I'm encountering some problems. 我从Angular JS开始尝试做这个项目,但是遇到了一些问题。
I know how to make routes using Angular JS the easy way, ie, if you have some specific .html files. 我知道如何使用Angular JS轻松进行路由,即如果您有一些特定的.html文件。
But how do you create something like a temporary .html file? 但是,如何创建类似.html临时文件的内容? Let me explain. 让我解释。
Let's say I have the main .html page of my CD store. 假设我有CD商店的.html主页。 You can make a quick search on my page and then you can click on a CD from a list of CD's in a vector. 您可以在我的页面上进行快速搜索,然后可以从矢量CD列表中单击CD。 I want to create a route for that specific CD without having an .html file for each CD. 我想为该特定CD创建路由,而不必为每个CD创建一个.html文件。 When you click you'd get something like http:.../AbbeyRoad or http:.../AbbeyRoad.html. 当您单击时,您将看到类似http:... / AbbeyRoad或http:... / AbbeyRoad.html的内容。
Any suggestions? 有什么建议么?
What you're after is route parameters. 您所追求的是路线参数。 You can do this: 你可以这样做:
.when('/Artist/:ArtistId/Album/:AlbumId', {
templateUrl: 'album.html',
controller: 'AlbumController'
}
The :
signifies that this is a parameter, and is passed in during navigation. :
表示这是一个参数,并在导航期间传递。 You can then use that parameter in your controller how you see fit (making API calls, creating markup, etc.). 然后,您可以在控制器中使用该参数,以使其感觉合适(进行API调用,创建标记等)。
Like this -- here is your controller: 这样-这是您的控制器:
.controller('ChapterController', function($scope, $routeParams) {
$scope.params = $routeParams;
})
and your view: 和您的看法:
<div>
Artist Id: {{params.ArtistId}}<br />
Album Id: {{params.AlbumId}}
</div>
Take a look at the $route documentation . 看一下$ route 文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.