Binding-EvalDotNotation

2-way skips a cycle of digest

by tbmpls

HTML

<div ng-app="myApp" ng-controller="MyCtrl">
  
    <table class="table">
        <thead>
            <th ng-repeat="field in fields">{{field}}__</th>
        </thead>
        <tr ng-repeat="row in rows">
            <th ng-repeat="field in fields">{{$eval('row.'+field)}}</th>
        </tr>
    </table>
</div>

JavaScript

function MyCtrl($scope) {
	  $scope.name = 'yaya'
    $scope.rows = [{
        info: {
            name: "Apple",
            category: "Fruit"
        },
        rate: {
            health: 100,
            ignored: true
        }
    },{
        info: {
            name: "Orange",
            category: "Fruit"
        },
        rate: {
            health: 100,
            ignored: true
        }
    },{
        info: {
            name: "Snickers",
            category: "Sweet"
        },
        rate: {
            health: 0,
            ignored: true
        }
    }]
    $scope.fields = ['info.name', 'info.category', 'rate.health']
}
angular.module('myApp', []);