2016-09-30 3 views
0

각도 응용 프로그램을 로컬로 실행할 수 없습니다. 내 interview.js와 angular.js가 발견되지 않는다는 오류가 나타납니다. 또한, 각도는 ide 콘솔에서 열 때 interview.js 파일에 정의되어 있지 않습니다. 여기 각도 응용 프로그램을 로컬로 실행할 수 없습니다.

mock 
public 
    index.html 
src 
    services 
    interview.js 
vendor 
    angular.js 

가 내 index.html을 여기에

<!doctype html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <meta http-equiv="x-ua-compatible" content="ie=edge"> 
    <title>Interview Practice</title> 
    <meta name="description" content=""> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <script src="../vendor/angular.js" type="text/javascript"></script> 
</head> 
<body ng-app="interviewapp"> 
    hello world! 

    <script src="../src/interview.js" type="text/javascript"></script> 
</body> 
</html> 

내가 HTTP 서버를 내 interview.js

angular.module("interviewapp", []); 
console.log("does this work"); 

사용하고 있습니다 : 여기

내 디렉토리 구조 응용 프로그램을 시작합니다.

Starting up http-server, serving ./public 
Available on: 
    http://10.66.87.184:8080 
    http://192.168.56.1:8080 
    http://127.0.0.1:8080 

이, 내가 오류입니다 localhost로가는, 또는 거기에 열거 된 HTTPS 중 하나를

http://10.66.87.184:8080/vendor/angular.js Failed to load resource: the server responded with a status of 404 (Not Found) 
http://10.66.87.184:8080/src/interview.js Failed to load resource: the server responded with a status of 404 (Not Found) 

어떻게이되도록 내 응용 프로그램이 실행 수정합니까?

+1

'src'와'vendor' 디렉토리를'public' 디렉토리로 옮기고 파일의 경로 시작 부분에서'..'를 제거하십시오. 'src = "../ src/interview.js"''를'src = "/ src/interview로 변경하십시오.js "' –

+0

cdn을 앵귤러에 연결하고 src 폴더에 대해 말한 내용을 수행했습니다. 왜 그 것이 효과가 있었는지 말할 수 있습니까? – McFiddlyWiddly

+1

설명이있는 답변이 추가되었습니다. –

답변

0
는 다음과 같이하는 프로젝트 구조를 변경

:

<script src="/vendor/angular.js" type="text/javascript"></script> 

이 :

<script src="../src/interview.js" type="text/javascript"></script> 
이에

<script src="../vendor/angular.js" type="text/javascript"></script> 

:

mock 
public 
    index.html 
    src 
    vendor 

도이를 변경 이

<script src="/src/interview.js" type="text/javascript"></script> 
그래서

당신의 자바 스크립트의 모든

은 공개 디렉토리에 있어야합니다. 또한 include 태그에 상대 경로를 사용하지 마십시오. 일반 사용자는 루트 폴더이므로 액세스 할 수 있어야합니다. 파일 예를 들어, 귀하의 경로의 시작부터

이동 srcvendor 디렉토리 public 디렉토리에과를 제거 .. : 주석에 명시된 바와 같이

2

서버가 루트 폴더로 public을 사용하고, 따라서 당신이 액세스하려는 다른 폴더를 볼 수 없기 때문에이 작동 src="../src/interview.js"

src="/src/interview.js"로 변경합니다. 폴더를 public 폴더로 이동하면 폴더에 액세스 할 수 있습니다.

0

서버에 public 폴더가 있습니다. 따라서 해당 폴더 내의 모든 항목은 호스트 이름을 통해 액세스 할 수 있습니다. 그러나 srcvendorpublic의 바깥쪽에 있으므로 서버를 통해 제공되지 않습니다. 그들에게 액세스하려면 public 폴더에 넣고 js 참조 전에 ..을 제거하십시오.

관련 문제