简体   繁体   English

网站以angular js打开时如何加载特定页面

[英]How to load a particular page when the website opens in angular js

I know it might be insanely easy but being new to angular I do not understand how to load a particular template as soon as the website is opened. 我知道这可能非常简单,但是刚开始接触角我不知道如何在打开网站后立即加载特定模板。 I have a template: 我有一个模板:

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

Which is linked to the following button on the nav bar: 链接到导航栏上的以下按钮:

   <li><a href='#/home'><span>Home</span></a></li>

How can I allow the website to load this particular template as soon as the URL of the website is entered Angular: 输入网址后,如何允许网站加载该特定模板Angular:

 myApp.config(['$routeProvider', function ($routeProvider, $routeParams) {
$routeProvider.when('/home', {
    templateUrl: 'home.html',
    controller: 'HomeCtrl'
})
 }]);

try this 尝试这个

<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>

You can use $routeProvider service. 您可以使用$routeProvider服务。 The method called otherwise can be used to set the route definition that will be used on route change when no other route definition is matched. 如果没有其他路由定义匹配,则可以使用otherwise调用的方法来设置将在路由更改中使用的路由定义。

Here's the documentation for the same. 这是相同的文档。 Also, they have elaborated this with an example here . 另外,他们在此处通过示例进行详细说明。

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

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