angularjs を使用してサービスから json 情報を取得する際に問題があります。
Google から例をダウンロードし、データベースから必要な情報を取得するように変更しました。しかし、機能していないようで、どこが壊れているのかわかりません。ここに私のservice.jsコードがあります:
angular.module('productServices', ['ngResource']).
factory('Product', function ($resource) {
return $resource('http://dev.integrator.blondgorilla.com/integratorservice/getproducts?min=0&max=15', {}, {
query: { method: 'GET', params: { ProductID: 'products' }, isArray: true }
});
});
コントローラーは次のようになります
function ProductListCtrl($scope, Product) {
$scope.products = Product;
}
product-list.html ページは次のようになります。
<div class="span10">
<!--Body content-->
<ul class="products">
<li ng-repeat="product in products" class="thumbnail">
<p>{{product.ProductID}}</p>
</li>
</ul>
</div>
メインの js ファイルは AngularSpike.js です
'use strict';
angular.module('ProsPhere', ['productFilters', 'productServices']).
config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/products', { templateUrl: 'partials/product-list.html', controller: ProductListCtrl }).
when('/products/:productId', { templateUrl: 'partials/product-details.html', controller: ProductDetailCtrl }).
otherwise({ redirectTo: '/products' });
}]);
私が使用および変更したコードは、次の場所にあります。
https://github.com/angular/angular-phonecat.git
ありがとうございました、
キアヌーシュ
これまでに見つけた2つの問題:
1-マレクが言った.query() 2-私は別のドメインを呼び出していたので、JSONPを使用する必要がありました
angular.module('productServices', ['ngResource']).
factory('Product', function ($resource) {
var test = $resource('http://dev.integrator.blondgorilla.com/integratorservice/getproducts', {}, {
query: { method: 'JSONP', params: { minid: '0', maxid: '70' }, isArray: true }
});
return test;
});
でもまだ商品が見えない