【问题标题】:How to solve the problem of passing ID as name of file to be loaded as ID.html?如何解决将ID作为文件名传递为ID.html的问题?
【发布时间】:2019-06-18 14:52:43
【问题描述】:

我有很多 html 页面,并决定使用它们的名称(简短且唯一)作为 id,所以当我想点击表格的一行时,id(即文件名)被传递到模板URL。例如,

app.config(function($routeProvider) {
    $routeProvider
    .when("/post/:id",
    {
        title: 'Disease',
        templateUrl : "/pages/posts/:id.html"
    })

例如,我的列表中有 Treponema.html、HeartDisease.html、LungCancer.html 等。当我单击一个时,它应该在页面右侧显示其内容,我已在该页面上声明:

<div ng-view></div>

当我点击一个列出的项目时,我会将它们的 id 作为名称(HearDisease、LungCancer)并将其放在 templateUrl 中。

<div id="HeartDisease" 
    onclick="window.location.href ='/post/'+this.id+'.html';>

     <p>HeartDisease.html</p>

</div>

【问题讨论】:

    标签: angularjs ngroute ng-view pass-data


    【解决方案1】:

    我认为更适合您的用例的是使用ng-include。看看页面底部你有一个例子。

    如果您想在浏览器中更新路由,您可以在控制器中使用$location 对象进行更新。

    【讨论】:

    • 但是有十几张卡片,并且链接在右侧打开。我如何使用 $location 对象做到这一点?
    猜你喜欢
    • 2018-08-16
    • 2022-01-15
    • 2011-07-06
    • 1970-01-01
    • 2016-07-30
    • 2023-02-09
    • 1970-01-01
    • 2015-09-06
    • 2020-10-02
    相关资源
    最近更新 更多