我是AngularJS的新人.
尝试创建第一个应用程序,并有问题.
有复选框列表
尝试创建第一个应用程序,并有问题.
有复选框列表
<div class='order-Box row-fluid' ng-repeat="order in orders" ng-model="orders"> <input type="checkBox" value="{{ order.id }}" ng-model="order.selected"> <div>
function OrdersCtrl($scope,Order){ $scope.orders = Order.query(); $scope.$watch('orders',function(v){ if (!v) return; alert(v); },true); }
主要目标是按所选复选框计算成本.
第二个问题:
在div上进行ng-repeat.所有重复的div都像
<div class="order-Box row-fluid ng-scope ng-pristine ng-valid" ng-repeat="order in orders" ng-model="orders">
这是正常的吗?
解决方法
尝试添加标志,或在jsfiddle
link上尝试.
function OrdersCtrl($scope,$timeout) { $scope.orders = []; var first = true; //this doesn't belong to any scope,it will be deallocated after the current cycle. var ajax = function () { $scope.orders = [{ id: 1,selected: true },{ id: 2,{ id: 3,{ id: 4,selected: true }]; }; $scope.$watch('orders',function (n,o) { if (first) { $timeout(ajax,2000); //simulate the ajax call. Assume data comes back in 2 seconds. } else { alert(n); } }); }