Javascript 当网站以js方式打开时,如何加载特定页面

Javascript 当网站以js方式打开时,如何加载特定页面,javascript,angularjs,Javascript,Angularjs,我知道这可能非常简单,但作为angular的新手,我不知道如何在网站一打开就加载特定的模板。 我有一个模板: <script type= "text/ng-template" id="home.html" ng-controller="HomeCtrl"> <h2 style="text-align: center;" >Welcome to the Admin Tools!</h2> </script> 试试这个 <script

我知道这可能非常简单,但作为angular的新手,我不知道如何在网站一打开就加载特定的模板。 我有一个模板:

 <script type= "text/ng-template" id="home.html" ng-controller="HomeCtrl">
 <h2 style="text-align: center;" >Welcome to the Admin Tools!</h2>
   </script>
试试这个

<script type="text/ng-template" id="/tpl.html">
       Content of the template.
</script>

<a ng-click="currentTpl='/tpl.html'" id="tpl-link">Load inlined template</a>
<div id="tpl-content" ng-include src="currentTpl"></div>

模板的内容。
加载内联模板

您可以使用
$routeProvider
服务。名为
否则
的方法可用于设置在没有其他路线定义匹配时用于路线更改的路线定义


相同的文档。此外,他们还通过一个示例对此进行了详细说明。

我已将路由添加到此页面,我将编辑代码以显示路由。但是,当用户进入站点时,我如何让它加载呢?您是否真正阅读了本教程?templateUrl参数是您所需要的全部。只需使用html模板的正确路径,并使其与tut中的一样。是的,但我现在有模板URL。如果我单击“主页”,它会显示模板,但我希望在用户尝试加载/index.htmlI时加载index.html#/homechoice@user3756848哦,对不起,我没能理解你的问题,否则是正确的。是的,这正是我需要的。谢谢,它正在工作是的,我现在已经接受了,它有时间限制,因此我不能马上做。你也可以使用
。当('/',options)
,这可能是更好的练习
,否则
应该重定向到“正确”页面(或“哇”风格的伪404)。
 myApp.config(['$routeProvider', function ($routeProvider, $routeParams) {
$routeProvider.when('/home', {
    templateUrl: 'home.html',
    controller: 'HomeCtrl'
})
 }]);
<script type="text/ng-template" id="/tpl.html">
       Content of the template.
</script>

<a ng-click="currentTpl='/tpl.html'" id="tpl-link">Load inlined template</a>
<div id="tpl-content" ng-include src="currentTpl"></div>