angular / angular.js

AngularJS - HTML enhanced for web apps!
https://angularjs.org
MIT License
58.85k stars 27.52k forks source link

ng-if + ng-repeat blocks the script when traceing $index on objectOfObjects #14713

Closed gp187 closed 8 years ago

gp187 commented 8 years ago

-- using only _ctrl.data.length with _ctrl.data as an object doesn't crash -- only ng-if with ng-repeat AND track by $index :: this is what crashes, with no error

Versions

"angular": "1.4.3", "angular-animate": "1.4.3", "angular-sanitize": "1.4.3",

Route

.state('base.rep',    {
              url         : "/rep",
              cache       : false,
              controller  : "myController as _ctrl",
              templateUrl : "views/rep.html",
              data        : { pageTitle: 'Report' }
          })

Script

_ctrl.data = [ 
      null, null, null, null, null, null, null, null, null, null, null, null, null, null, 
      {id: "54433", name: "54333", on: true }, 
      {id: "43223", name: "43223", on: true }
]

Template

<div class="row" ng-if="_ctrl.data.length">
    <div class="col">
      <div class="card">
          <div class="card-header padding block row-center"><h4 class="pull-left">Choose</h4></div>
          <div class="row row-center" ng-repeat="si in _ctrl.data track by $index">
            <p>Sensor #{{si}}</p>
            <label class="toggle toggle-positive">
               <input type="checkbox" ng-model="_ctrl.data[si].on"><div class="track"><div class="handle"></div></div>
            </label>
          </div>
      </div>
    </div>
  </div>
Narretz commented 8 years ago

I can't reproduce the crash with your example code: http://plnkr.co/edit/UtXwioP6nE8x8Zxe6Zyj?p=preview

But I also don't see an object of objects in your code.

gp187 commented 8 years ago

Weirdly enough I can't replicate it either now. But the behavior was very consistent at the time of issue. If I find it again, I'm posting it with a plunkr