简体   繁体   English

Angular js从哪个文件开始执行?

[英]From which file does Angular js execution start?

I have a angular js project. 我有一个有角度的js项目。 I downloaded the seed project and made some changes. 我下载了种子项目并进行了一些更改。 I am able to run it. 我能够运行它。 When I start the server, i have to manually go to localhost:portnum/app/index.html to run the index.html" 启动服务器时,我必须手动转到localhost:portnum / app / index.html来运行index.html”

How can i configure that when i type my localhost/portnum, it should redirect to index.html directly. 当我键入localhost / portnum时,应如何配置它,它应该直接重定向到index.html。 I have gone through many angular projects. 我经历了许多棱角分明的项目。 I am not able to understand where does the angular execution start. 我无法理解角度执行从哪里开始。 I mean, from where does the execution begin. 我的意思是,执行从哪里开始。 There are lot many js files. js文件很多。 Kindly help in this regard. 在这方面请提供帮助。

Sabarisri Subramaniyan 萨巴里斯里·苏布拉玛尼扬

I agree that it isn't an angular issue. 我同意这不是一个尖锐的问题。 Your web server will make what ever directory you tell it to the root of your website/app. 您的网络服务器会将您告诉它的所有目录都放置到​​网站/应用程序的根目录。 One really simple way you could handle this (this is what I do when testing on localhost): 一种可以处理此问题的非常简单的方法(这是在localhost上进行测试时要做的事情):

if you have python installed use the python simple http server: 如果您已安装python,请使用python简单的http服务器:

first change into your app directory: 首先进入您的应用目录:

cd /app

then run the python simple http server from inside of that directory: 然后从该目录内部运行python简单的http服务器:

python -m SimpleHTTPServer 8080

the server is smart enough to know that index.html is the first page it should load, so all you have to do now is go to your browser and type: 服务器足够聪明,知道index.html是它应该加载的第一页,因此,现在要做的就是转到浏览器并键入:

http://localhost:8080

done. 完成。

There are other web servers that will accomplish this same thing. 还有其他Web服务器将完成相同的任务。 the important thing to remember is that it will look inside whatever folder you designate as the root folder. 要记住的重要一点是,它将在您指定为根文件夹的任何文件夹中查找。 By launching the python simple server while inside of the /app folder, that folder will be set as the root. 通过在/ app文件夹中启动python简单服务器,该文件夹将被设置为根目录。 Most web servers will know that index.html is the first page of the site just from the common use of "index". 大多数Web服务器仅从“索引”的常用用法就知道index.html是站点的首页。

Good luck! 祝好运!

Use Routes like below 使用如下路线

var app = angular.module('app', []);

// configure our routes
app.config(function($routeProvider) {
    $routeProvider

        // route for the home/default page
        .when('/', {
            templateUrl : 'pages/home.html',
            controller  : 'homeController'
        })
        .when('/page1', {
            templateUrl : 'pages/otherpage1.html',
            controller  : 'otherpage1Controller'
        })
        .when('/page2', {
            templateUrl : 'pages/otherpage2.html',
            controller  : 'otherpage2Controller'
        });
});

Check this Link : http://docs.angularjs.org/api/ngRoute .$routeProvider 检查此链接: http ://docs.angularjs.org/api/ngRoute。$ routeProvider

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

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