2014-09-02 85 views
1

也許是一個愚蠢的問題,但我沒有成功地將角度網站視爲本地主機。 這是網站,我下載:https://github.com/kenyee/angularjs-cart霍我可以查看本地主機的角度網站

我只看到標題ANG得到錯誤控制檯:

"XMLHttpRequest cannot load file:///C:/Users/--name--/Dropbox/angularjs-cart-master/angularjs-cart-master/ShoppingCart/partials/store.htm. Received an invalid response. Origin 'null' is therefore not allowed access. " 

感謝您的幫助!

回答

0

在localhost中查看AngularJS網站應該沒有問題。 AngularJS是客戶端。

編輯:我下載並檢查了所有頁面給你。它裝載在我身邊很好。請記住,既然AngularJS是客戶端,你不需要服務器。而不是在本地主機上運行它(我假設XAMPP或者你正在使用的東西),只需右鍵單擊+用瀏覽器打開即可。

記得首先打開主html(default.html),也許在跳入AngularJS之前閱讀一些html/css/js文檔!

祝你好運!

+0

謝謝..我按照你說的方式打開它(右鍵點擊+用瀏覽器打開),我的錯誤。我無法看到該網站... – user3944498 2014-09-02 16:05:16

2

如果URL說明類似於file:/// C:/ Users/...它不在本地主機上運行..它只是作爲文件打開。

它需要從「服務器」跑..

如果使用Windows添加的文件夾上IIS網站,在Mac上使用類似甲基苯丙胺..

或打開一個文件夾爲您自動運行服務器的IDE(編輯器),如Visual Studio或Brackets。

如果你可以讓我知道你使用我可以添加更多的信息,如果你需要它。

更新:雖然這是真的一個原始角頁面是客戶端,並不需要從服務器運行..如果它從本地文件系統拉其他文件。 (即腳本/ css /模板/部分),它需要在服務器上運行,因爲瀏覽器無法訪問文件系統,除非通過服務器提供文件。(出於安全原因)

+0

對不起,我的意思是隻需點擊default.html文件打開網站。我必須有服務器? – user3944498 2014-09-02 16:03:20

0
If You have Xampp installed on your system then put ShoppingCart folder in 
    xampp/htdocs folder` 

    After This hit the url 
    [http://localhost/ShoppingCart/#]. 
    It will work as this application on my system. 
0

您肯定需要本地服務器(Windows上的WAMP或Linux上的Lamp)才能像David Beech所建議的那樣運行Angular應用程序。在我的情況下,我無法弄清楚爲什麼從Plunk這個簡單的Angular檢查表格代碼無法在我的電腦上正常工作(它似乎沒有引導CSS代碼)。

<body ng-app="formExample"> 
 
    <div ng-controller="ExampleController"> 
 
    <form novalidate class="css-form"> 
 
    Name: <input type="text" ng-model="user.name" required /><br /> 
 
    E-mail: <input type="email" ng-model="user.email" required /><br /> 
 
    Telephone: <input type="number" ng-model="user.number" required /><br /> 
 
    <input type="submit" ng-click="update(user)" value="Save" /> 
 
    </form> 
 
</div> 
 

 
<style type="text/css"> 
 
    .css-form input.ng-invalid.ng-touched { 
 
    background-color: #FA787E; 
 
    } 
 

 
    .css-form input.ng-valid.ng-touched { 
 
    background-color: #78FA89; 
 
    } 
 
</style> 
 

 
<script> 
 
    angular.module('formExample', []) 
 
    .controller('ExampleController', ['$scope', function($scope) { 
 
     $scope.master = {}; 
 

 
     $scope.update = function(user) { 
 
     $scope.master = angular.copy(user); 
 
     }; 
 

 
     $scope.reset = function() { 
 
     $scope.user = angular.copy($scope.master); 
 
     }; 
 

 
     $scope.reset(); 
 
    }]); 
 
</script> 
 
</body>

我做了我在谷歌搜索,發現Single Page Angular App這個很好的例子,它說:你需要一些當地的環境,否則角路由將無法正常工作。我解僱了我的Wamp服務器,把代碼放到了「www」目錄下,然後看,角度觸發的css工作得很好。

相關問題