【问题标题】:Link to HTMl file in another folder and update URL链接到另一个文件夹中的 HTMl 文件并更新 URL
【发布时间】:2018-05-23 20:05:00
【问题描述】:

在我的控制器中,我有一个字符串数组,这些字符串定义了我想从中获取 index.html 的文件夹名称(假设所有文件夹都有一个 index.html):

$scope.folderNames = ['DCB', etc]

我想在我的 HTML 页面上为这些文件中的每一个提供一个链接;单击时,URL 应该以这种模式更新:

baseURL/folderNames/ --> baseURL/folderNames/DCB

在这种情况下,应该显示 DCB 的 index.html。

目前,我正在做:

<table>
    <tr ng-repeat="folder in folderNames">
        <td>
            <!-- Not sure what to put here to load HTML file from another folder -->
        </td>
</table>

我以前使用 ui-sref 并从 ng-repeat 传入 folderName 以进入不同的状态,像这样更新 URL:

$stateProvider
    .state('folderNames', {
        url: '/BASEURL/folderNames',
        templateUrl: 'PATH_TO_FOLDER_NAMES_HTML/view.html
    })
    .state('folderNames.view' {
        url: /:folder,
        templateUrl: 'PATH_TO_FOLDER/index.html
    });

但是现在,当我从文件夹页面单击文件夹名称时,webapp 将 PATH_TO_FOLDER 从 folderNames.view 的 templateUrl 附加到 URL,这不是我想要的。我在想我不应该使用 ui-sref,因为我不想在状态转换,而是想从我的项目目录中的另一个文件夹中显示一个 HTML 文件。

如何更新 URL 以包含我刚刚单击的文件夹名称,然后显示该文件夹名称中的 index.html?

【问题讨论】:

    标签: javascript java html angular


    【解决方案1】:

    只需在ng-href类似的东西中使用插值:

    <a ng-href="{{baseURL +'/' + folderNames +'/' + folder}}">{{folder}}</a>
    

    这假设您在范围内有变量,例如

    $scope.baseURL = '/appDirectory';
    $scope.folderNames = 'images';
    

    【讨论】:

      【解决方案2】:

      只好放了

       <a href="path/index.html"></a>
      

      叹息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-01-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-12-28
        • 2018-02-26
        • 2019-11-19
        • 2021-03-22
        相关资源
        最近更新 更多