2017-06-27 46 views
0

我正在做角度路由並出現此錯誤。使用角度路由時出現錯誤只有協議方案支持跨域請求:http

這是我的html文件

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <script src="../Scripts/angular.min.js"></script> 
    <script src="../Scripts/angular-route.min.js"></script> 
    <script src="../Scripts/test.js"></script> 

    <script src="../Controllers/about.js"></script> 
    <script src="../Controllers/contact.js"></script> 
    <script src="../Controllers/home.js"></script> 
    </head> 
    <div ng-app="MyApp"> 
    <body> 
     <div class="navbar-header"> 
     <nav> 
      <ul> 
      <li><a href="#!/">Home</a></li> 
      <li><a href="#!/about">About Us</a></li> 
      <li><a href="#!/contact">Contact Us</a></li> 
      </ul>   
     </nav> 
     </div> 

     <div ng-view> 
     </div> 

    </body> 
    </div> 
</html> 

這是我的js文件。

var myapp= angular.module('MyApp',['ngRoute']); 
myapp.config(function($routeProvider) { 

    $routeProvider 
    .when('/',{ 
    templateUrl: 'home.html', 
    controller: 'mainController' 
    }) 
    .when('/about',{ 
    templateUrl: 'about.html', 
    controller: 'aboutController' 
    }) 
    .when('/contact',{ 
    templateUrl: 'contact.html', 
    controller: 'contactController' 
    }); 

}); 
+3

的可能的複製[AngularJS錯誤:交叉原點請求僅支持的協議方案:HTTP,數據,鉻延伸,HTTPS(https://stackoverflow.com/questions/ 27742070/angularjs誤差交原點請求-是僅支持換協議的方案) –

回答

0

嘗試檢查下面的代碼。我希望這能幫到您。

<!DOCTYPE html> 
 
<html> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js"></script> 
 
<body> 
 

 
<div ng-app="MyApp"> 
 

 
     <div class="navbar-header"> 
 
     <nav> 
 
      <ul> 
 
      <li><a href="#!/">Home</a></li> 
 
      <li><a href="#!about">About Us</a></li> 
 
      <li><a href="#!contact">Contact Us</a></li> 
 
      </ul>   
 
     </nav> 
 
     </div> 
 

 
     <div ng-view> 
 
     </div> 
 

 
</div> 
 

 
<script> 
 
var myapp= angular.module('MyApp',['ngRoute']); 
 
myapp.config(function($routeProvider) { 
 

 
    $routeProvider 
 
    .when('/',{ 
 
    template: 'home page', 
 
    // controller: 'mainController' 
 
    }) 
 
    .when('/about',{ 
 
    template: 'about page', 
 
    // controller: 'aboutController' 
 
    }) 
 
    .when('/contact',{ 
 
    template: 'contact page', 
 
    //controller: 'contactController' 
 
    }); 
 

 
}); 
 
</script> 
 

 
<p>You can write the date in many different formats.</p> 
 

 
</body> 
 
</html>

相關問題