2014-02-15 29 views
0

我忙於嘗試學習Angular + Typescript + bootstrap,我偶然發現了一個我無法解決的問題。我有一個NG-重複在一個局部視圖:只能在IE中工作的ng-repeat

<div> 
<h1>Debtors</h1> 
<table class="table table-hover"> 
    <thead> 
     <tr> 
      <th>Debtor</th> 
      <th class="col-sm-1"></th> 
      <th class="col-sm-1"></th> 
     </tr> 
    </thead> 
    <tbody> 
     <tr ng-repeat="Debtor in vm.Debtors"> 
      <td>{{Debtor.Name}}</td> 
      <td><a href="" ng-click="vm.EditDebtor(Debtor.ID)"><i class="fa fa-pencil fa-fw fa-lg"></i> Edit</a></td> 
      <td><i class="fa fa-trash-o fa-fw fa-lg"></i> Delete</td> 
     </tr> 
    </tbody> 
</table> 

與控制器:

module Controllers 
{  
export class DebtorsController 
{ 
    static $inject = ['$scope', '$http', '$modal']; 
    Debtors: Models.TradePartyModel[]; 
    ModalService: ng.ui.bootstrap.IModalService; 

    constructor($scope: ng.IScope, $http: ng.IHttpService, $modal: ng.ui.bootstrap.IModalService) 
    { 
     this.ModalService = $modal; 

     $http.get("http://localhost:51263/api/debtors/1") 
      .success((Debtors) => 
      { 
       this.Debtors = Debtors; 
      });    
    }   
} 
} 

路由定義爲:

$routeProvider.when('/Debtors/ViewDebtors', { 
    templateUrl: 'App/Views/Debtors/Debtors.html', 
    controller: Controllers.DebtorsController, 
    controllerAs: "vm" 
}); 

這工作完全正常在IE中,它會顯示錶格和所有數據,但在FireFox或Chrome中似乎不起作用。我檢查過提琴手,數據恢復正常,但表格沒有顯示。

任何想法?謝謝!

+0

任何控制檯錯誤?您是否安裝了Chrome Angular擴展程序以在Debtors返回後驗證範圍? – Scott

+0

在Firefox控制檯中沒有錯誤,chrome給出了這個錯誤:GET http:// localhost:51263/api/debtors/1 angular.js:7889 (匿名函數)angular.js:7889 sendReq angular.js: 7720 $ http.serverRequest angular.js:7454個 wrappedCallback angular.js:10655個 wrappedCallback angular.js:10655 (匿名函數)angular.js:10741 範圍$ EVAL angular.js:11634 範圍$消化angular.js:11479 $代表.__原__ $消化VM48:844 範圍$適用angular.js:。11740 $代表.__原__ $適用VM48:855 (匿名函數)angular.js:8950 jQuery的。 event.dispatch jquery-1。 9.1.js:3074 elemData.handle – user1435899

+0

不完全確定角度擴展是如何工作的,但它在根作用域下提供了三個作用域,一個根作用域和兩個兄弟作用域。第二個範圍說:這個範圍沒有模型,第三個範圍有:vm:{ModalService:{...}} – user1435899

回答

1

好了,所以在解決這個嘗試幾次後,Chrome的決定吐出這個錯誤了:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. 

在服務器上啓用CORS固定我的問題。看起來像它現在在所有瀏覽器上工作。