【问题标题】:Can I load views from inside another partial view in Angular JS 1.5?我可以从 Angular JS 1.5 的另一个局部视图中加载视图吗?
【发布时间】:2020-07-19 14:38:55
【问题描述】:

所以我已经在部分视图中(..someURL.aspx?id=xx#/insidePartialOrTemplateView.html),我不在 index.html 中,如上所述。在这个局部视图内部是一些 div/navigation/buttons/,我想在其中加载其他视图。因此,在我目前的部分视图中,它就像一个全新的其他网站。

-------------------------------------
|profile |                          |
|settings|                          |
|gallery |  load views here         |
|        |                          |
|        |                          |
-------------------------------------

示例代码:

<script type="text/ng-template" id="user">
<nav>
    <ul>
        <li><a href=#/userProfile></a></li>
        <li><a href=#/userSettings></a></li>
        <li><a href=#/userGallery></a></li>
    </ul>
</nav>
</script>

在这种情况下也用于路由

angular.module("PageRouting", ["ngRoute"])
    .config(function ($routeProvider) {
        $routeProvider
            .when("/userProfile", {
                templateUrl: "sample1.html"
            })
            .when("/userSettings", {
                templateUrl: "sample2.html"
            })
            .when("/userGallery", {
                templateUrl: "sample3.html"
            })
    })

有没有可能的解决方案?我正在使用角度 1.5。我是角度新手,什么都不知道。我不熟悉更高版本。

【问题讨论】:

    标签: angularjs


    【解决方案1】:

    理论上,您可以根据需要在彼此内部加载任意数量的模板。 这里有两个例子:

     <script type="text/ng-template" id="/tpl.html">
      Content of the template.
    
      <a ng-click="currentTpl2='/tpl2.html'" id="tpl-link">Load inlined template2</a>
    
      <div id="tpl-content2" ng-include src="currentTpl2"></div>
    
      <script type="text/ng-template" id="/tpl2.html">
        Content of the template2.
      </script>
    </script>
    
    <a ng-click="currentTpl='/tpl.html'" id="tpl-link">Load inlined template</a>
    <div id="tpl-content" ng-include src="currentTpl"></div>
    

    【讨论】:

    • 感谢您的关注。我发现,我试图做的事情是不可能的。由于已经有指向我的局部视图的路线,因此无法在该局部视图中创建路线。
    猜你喜欢
    • 2017-09-01
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-31
    相关资源
    最近更新 更多