2
我正在开发一个页面的应用程序,并且我想要调用服务器来查询特定价格的物品(例如www.myapp.com/products?price = 1200)。我能够执行请求并从端点获取JSON,但该视图不更新并显示数据。任何想法为什么我的观点不更新?AngularJS - 发送和接收数据但不更新视图
我的第一个想法是,问题是在$ routeProvider,但我不知道我需要如何改变它。
谢谢!
我的角度模块
angular.module('myApp', [])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/products',
{ templateUrl: 'partials/productSearchTemplate.html',
controller: ProductControl
});
}]);
我控制器
function ProductControl($scope, $http) {
$scope.sendRequest = function() {
$http({
url: '/products',
method: "GET",
query: {price: $scope.price}
}).success(function(data) {
$scope.products = data;
});
}
}
我的观点
<div class="products">
<div ng-repeat="product in products" class='product-panel'>
<div class='front'>
<span class='product-title'>{{product.title}}</span><br/>
<span class='product-manufacturer'>
{{product.manufacturer}}
</span>
</div>
<div class='back'>
<span class='product-price'>
{{product.price}}
</span><br/>
<a href="{{product.url}}">Details</a>
</div>
</div>
</div>
从哪一点你要sendRequest –
我在我的index.html页面有一个按钮 –
如果你的按钮不在productSearchTemplate中,因此我怀疑它没有权限访问ProductControl的范围,因此无法调用sendRequest。 – mfelix