简体   繁体   English

在AngularJS中的同一HTML页面上显示不同的数据

[英]Display different data on same HTML page in AngularJS

I'm making a website in AngularJS exactly like this one: http://www.aboveandbeyond.nu 我在AngularJS中创建了一个完全像这样的网站: http ://www.aboveandbeyond.nu

There is a page in the website where I'm displaying a list of links using ng-repeat, I'm taking the data from a JSON file. 网站上有一个页面,我正在使用ng-repeat显示链接列表,我正在从JSON文件中获取数据。 What I want is when somebody clicks on a particular link I need to display a particular set of data on a new page respective to the link. 我想要的是当有人点击特定链接时,我需要在链接的新页面上显示一组特定数据。 For reference you may check the functionality of this page: http://www.aboveandbeyond.nu/abgt 作为参考,您可以查看此页面的功能: http//www.aboveandbeyond.nu/abgt

I can not do this using Routing because there are a lot of links and I dont want to create new page for each link separately, so routing is not a feasible option. 我不能使用路由,因为有很多链接,我不想分别为每个链接创建新页面,因此路由不是一个可行的选择。 What else can I do to achieve this? 我还能做些什么来实现这个目标?

EDIT 1: 编辑1:

this is a part of the code which displays the list of podcast: 这是显示播客列表的代码的一部分:

<div id="track-list" ng-repeat="track in tracks | filter:search | orderBy: '-date'">
        <a ng-href="#/radio"><h3 class="track-list-title">{{track.title}}</h3></a>
        <p class="track-list-date">{{track.date | date}}</p>
</div>

this is the JSON data inside of a controller (it is a sample data): 这是控制器内部的JSON数据(它是一个示例数据):

mainApp.controller('podcastController', function($scope) {
$scope.pageClass = 'page page-podcast';
$scope.tracks =[
    {title:'Group Therapy 156 with Above & Beyond and Maor Levi', date: new Date(), link:'#'},
    {title:'Group Therapy 156 with Above & Beyond and Maor Levi', date: new Date(), link:'#'},
    {title:'Group Therapy 156 with Above & Beyond and Maor Levi', date: new Date(), link:'#'},
    {title:'Group Therapy 156 with Above & Beyond and Maor Levi', date: new Date(), link:'#'},
    {title:'Group Therapy 156 with Above & Beyond and Maor Levi', date: new Date(), link:'#'},
    {title:'Group Therapy 156 with Above & Beyond and Maor Levi', date: new Date(), link:'#'},
    {title:'Group Therapy 156 with Above & Beyond and Maor Levi', date: new Date(), link:'#'},
    {title:'Group Therapy 156 with Above & Beyond and Maor Levi', date: new Date(), link:'#'},
    {title:'Group Therapy 156 with Above & Beyond and Maor Levi', date: new Date(), link:'#'},
    {title:'Group Therapy 156 with Above & Beyond and Maor Levi', date: new Date(), link:'#'},
    {title:'Group Therapy 156 with Above & Beyond and Maor Levi', date: new Date(), link:'#'}
];});

but ultimately i will ahve to fetch info from this place: 但最终我会从这个地方获取信息:

http://musichighcourt.com/soundcloudapp/play_life/podcast/get_podcast.php http://musichighcourt.com/soundcloudapp/play_life/podcast/get_podcast.php

Your help is appreciated Thank you 感谢您的帮助谢谢

Use the power of dynamic routing. 使用动态路由的力量。

example using $stateProvider: 使用$ stateProvider的示例:

$stateProvider
.state('artist.detail', {
    url: "/artist/:contactId",
    templateUrl: 'artist.detail.html',
    controller: <controller-name>
})

Dynamic routing is amazing but it's hard to be able to explain it on stackoverflow alone. 动态路由是惊人的,但很难单独在stackoverflow上解释它。

It's something you have to look into if you want to build any kind of web application that uses API's to fetch information. 如果您想构建任何使用API​​来获取信息的Web应用程序,那么您必须要考虑这些问题。

Basically, dynamic routing allows you to get parameters from the dynamic url like /artist/:name where you can get the :name parameter from the url. 基本上,动态路由允许您从动态URL获取参数,例如/ artist /:name,您可以从url获取:name参数。

Then, using the :name parameter you got from the url, you can fetch the artist out of the JSON file, database or whatever you're using and display relative information based on the url. 然后,使用您从URL获取的:name参数,您可以从JSON文件,数据库或您正在使用的任何内容中获取该艺术家,并根据该URL显示相关信息。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM