2017-05-23 24 views
0

こんにちは私は、データベース内のブランドテーブルにコードと名前があります。 Angularjsを使ってブランドリストを取得しようとしています。私のWebサービスでanglejsのデータベースからデータを読み込む方法C#

var app = angular.module("myApp", []); 
app.controller("CateCtrl", function ($scope, $http) { 
    $scope.ShowBrandList(); 

    //Show from DB 
    $scope.ShowBrandList = function() { 
var httpreq = { 
    method: 'POST', 
    url: 'Brand.aspx/GetBrandList', 
    headers: { 
     'Content-Type': 'application/json; charset=utf-8', 
     'dataType': 'json' 
    }, 
    data: {} 
} 
$http(httpreq).success(function (response) { 
    $scope.brandList = response.d; 
}) 
}; 

}); 
私Brand.aspx.csで

[WebMethod] 
    public List<Master_BrandBLL> GetBrandList() 
    { 
     return Master_BrandBLL.GetALLBrands(); 
    } 
Brand.aspx

<div ng-app="myApp" ng-controller="CateCtrl"> 
        <table class="table table-bordered table-hover table-striped" cellpadding="0" cellspacing="0"> 
         <thead> 
          <tr> 
           <th> 
            No 
           </th> 
           <th> 
            Code 
           </th> 
           <th> 
            Name 
           </th> 
          </tr> 
         </thead> 
         <tbody> 
          <tr ng-repeat="brand in brand.brandList"> 
           <td> 
            {{$index}} 
           </td> 
           <td> 
            {{ brand.Code }} 
           </td> 
           <td> 
            {{ brand.Name }} 
           </td> 
          </tr> 
         </tbody> 
        </table> 
       </div> 

jQueryを使って細かい作業。しかし、それはangularjsで何も表示することはできません。

+0

'$ scope.brandList = response.dを;'なぜ ".D" と – PinBack

答えて

0

コントローラを介してBrandListを参照する必要があります。あなたのngのリピートは次のようになります。

ng-repeat = "brand in CateCtrl.brandList" 
+0

なぜ「CateCtrl NGリピートでbrandListを使用します.brandList "!?brandListは十分だと思います。 – Maher

+0

私の眼鏡が吸うからです。私はあなたがcontrollerAsを使っていたと誓っていたかもしれません。あなたはそうしなければなりません。 :)ここで推奨するガイドラインに従うことをお勧めできません:github.com/johnpapa/angular-styleguide/tree/master/a1。 - Mike Feltman 9分前 –

0

このお試しください:

<tr ng-repeat="brand in brandList"> 
関連する問題