当我加载索引页面时,我的ajax调用有效并且范围确实已设置。但似乎在使用"产品"。
设置范围之前加载ng-repeat我觉得应该有办法
干杯!
products.controller.js
dvpModule.controller("ProductsController", function ($scope, productRepository) {
productRepository.get().then(function(products) {
$scope.products = products;
});
});
产品-repository.js
dvpModule.factory('productRepository', function($http, $q) {
return {
get: function() {
var deferred = $q.defer();
$http({
method: 'POST',
url: 'http://localhost/test/wp-admin/admin-ajax.php',
params: { action: 'getAllProductUrls' },
}).success(deferred.resolve).error(deferred.reject);
return deferred.promise;
}
};
});
的index.html
<html ng-app="dvpModule">
<head>
<script type='text/javascript' src='js/angular.min.js'></script>
<script src="js/scripts/dvp_module.js" /></script>
<script src="js/scripts/products-controller.js" /></script>
<script src="js/scripts/products-repository.js" /></script>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<title>DVP {{2 + 2}}</title>
</head>
<body ng-controller="ProductsController">
<div>
<tr ng-repeat="product in products">
<th>{{product.Category}}</th>
<th>{{product.Features}}</th>
<th>{{product.MODEL_SERIES}}</th>
</tr>
</div>