ng-repeat仅在IE中工作

时间:2014-02-15 17:38:24

标签: angularjs typescript

我正忙着学习Angular + Typescript + bootstrap,我偶然发现了一个我无法解决的问题。我在局部视图中有一个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。我已经检查过fiddler并且数据正确地返回,但表格没有显示。

任何想法?谢谢!

1 个答案:

答案 0 :(得分:1)

好的,所以经过几次尝试修复后,Chrome决定吐出这个错误:

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

在服务器上启用CORS修复了我的问题。看起来它现在适用于所有浏览器。