2014-12-26 2 views
2

를로드하지 못했습니다, 여기 내 코드입니다 : app.jsAngularJS와 내가 AngularJS와 지시어로 노력하고 템플릿을

<!DOCTYPE html> 
<html lang="en" ng-app="myapp"> 
<head> 
    <meta charset="UTF-8"> 
    <title>Directive</title> 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.js"></script> 
    <script type="text/javascript" src="app.js"></script> 
</head> 
<body> 
    <photo photo-src="abc.jpg" caption="This is so Cool" /> 
</body> 
</html> 

index.html을

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

app.directive('photo',function(){ 
    return { 
     restrict: 'E', 
     templateUrl: 'photo.html', 
     replace: true, 
     scope: { 
      caption: '@', 
      photoSrc: '@' 
     } 
    } 
}); 

photo.html

나는 파일을 테스트합니다. 브라우저에 직접 입력하십시오. 그것은 Firefox에서 잘 작동하지만, IE & 크롬에서는 작동하지 않습니다. 두 IE 모두 & 크롬 쇼 오류 Failed to load template

어떻게 해결할 수 있습니까?

+0

네트워크에서 어떤 경로가로드를 시도하는지 확인하십시오. – PSL

+0

@PSL로드하려는 경로가 정확합니다. 이것은 '오류 :'XMLHttpRequest '에서'send '를 실행하지 못했습니다 :'file : /// E :/www/lab/angularjs/directive/photo.html '을로드하지 못했습니다. " – user1995781

+1

ie 파일 프로토콜을 사용하여로드하려고하기 때문에 호스팅되지 않았습니까? 원산지 부족이 문제가되지 않도록 보안을 해제해야로드 할 수 있습니다. – PSL

답변

3

당신은 HTTP 웹 서버에서 호출해야하거나 아래와 같은 스크립트 태그로 동일한 파일에 템플릿을 작성할 수 있습니다 크롬

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

자사의 보안 문제를 해결합니다. Chrome은 도메인 간 요청을 허용하지 않습니다. 시동 크롬을 --disable-웹 보안

와 Windows의 경우 :

chrome.exe의 --disable-웹 보안 맥에

:

/응용 프로그램/구글 \ Chrome.app/ --args --disable-web-security

이렇게하면 도메인 간 요청이 허용됩니다. 웹 보안을 사용할 수 없음을 기억하십시오.

걱정하지 마세요, 파일을 호스팅 할 때 작동합니다.