加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS在加载内容后开始观看

发布时间:2020-12-17 17:40:13 所属栏目:安全 来源:网络整理
导读:我是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 订单是在加载页面上通
我是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>

订单是在加载页面上通过ajax查询从服务器填充的.

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);
        }
    });
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读