简体   繁体   English

链接到另一个文件夹中的HTMl文件并更新URL

[英]Link to HTMl file in another folder and update URL

In my controller, I have an array of strings that define folder names from which I want to grab index.html from (assume all folders have an index.html): 在我的控制器中,我有一个字符串数组,这些字符串定义了要从其中获取index.html的文件夹名称(假设所有文件夹都具有index.html):

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

I want to have a link on my HTML page for each of these files; 我想在HTML页面上为每个文件提供一个链接; when one is clicked, the URL should be updated in this pattern: 当单击一个时,URL应该以以下方式更新:

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

and in this case, DCB's index.html should show up. 在这种情况下,应显示DCB的index.html。

Currently, I am doing: 目前,我正在做:

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

I was previously using ui-sref and passing in folderName from the ng-repeat to go to a different state, updating the URL like so: 我以前使用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
    });

But now when I click on a folderName from the folders page, the webapp appends PATH_TO_FOLDER from folderNames.view's templateUrl to the URL, which isn't what I want. 但是现在,当我从文件夹页面单击folderName时,Web应用程序会将folderNames.view的templateUrl中的PATH_TO_FOLDER附加到URL上,这不是我想要的。 I'm thinking that I shouldn't be using ui-sref because rather than a transition in state, I just want to show an HTML file from another folder in my project directory. 我在想我不应该使用ui-sref,因为我不想显示状态转换,而只是想显示项目目录中另一个文件夹中的HTML文件。

How would I go about updating the URL to include the folderName that I just clicked on, and then displaying the index.html from that folderName? 我将如何更新URL以包括我刚刚单击的folderName,然后显示该folderName中的index.html?

Just use interpolation in ng-href something like: 只需在ng-href使用插值,例如:

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

This assumes you have variables in scope like 假设您在范围内有变量,例如

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

just had to put 只是不得不把

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

sigh. 叹。

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

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