Error creating table with angular js

0

I'm trying to replicate an example I found on the net to create a table with angular js. But this is returning the error of the link:

link

 function consoleLog(type) {
  var console = $window.console || {},
      logFn = console[type] || console.log || noop,
      hasApply = false;

  // Note: reading logFn.apply throws an error in IE11 in IE8 document mode.
  // The reason behind this is that console.log has type "object" in IE8...
  try {
    hasApply = !!logFn.apply;
  } catch (e) {}

  if (hasApply) {
    return function() {
      var args = [];
      forEach(arguments, function(arg) {
        args.push(formatError(arg));
      });
      return logFn.apply(console, args); <-- nesta linha o erro é apontado
    };
  }

I've never used it, so I do not know what to do.

    
asked by anonymous 07.04.2016 / 16:59

1 answer

0

Complete example and working with angularjs

<head>
<link data-require="[email protected]" data-semver="3.0.3" rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" />
<script src="js/teste/angular.min.js"></script>
<script src="js/teste/jquery-1.7.2.min.js"></script>
<link rel="stylesheet" href="style.css" />

<script>
    var app = angular.module("app", []);

    app.controller('table_controller', function($scope) {
        $scope.ordered_columns = [];
        $scope.all_columns = [{
            "title": "name",
            "type": "string",
            "checked": true
        }, {
            "title": "age",
            "type": "number",
            "checked": true
        }, {
            "title": "city",
            "type": "string",
            "checked": true

        }, {
            "title": "state",
            "type": "string",
            "checked": false
        }, {
            "title": "job",
            "type": "string",
            "checked": false
        }];

        // i.e. the rows
        $scope.data = [{
            "name": "aleck",
            "age": 33,
            "city": "Portland",
            "state": "OR",
            "job": "developer"
        }, {
            "name": "john",
            "age": 40,
            "city": "Portland",
            "state": "OR",
            "job": "designer"
        }, {
            "name": "erik",
            "age": 34,
            "city": "Portland",
            "state": "OR",
            "job": "sales"
        }];

        $scope.$watch('all_columns', function() {
            update_columns();
        }, true);

        var update_columns = function() {
            $scope.ordered_columns = [];
            for (var i = 0; i < $scope.all_columns.length; i++) {
                var column = $scope.all_columns[i];
                if (column.checked) {
                    $scope.ordered_columns.push(column);
                }
            }
        };
    });
</script>
</head>

 <body ng-app="app" ng-controller="table_controller">
  <h2>Dynamic table columns with AngularJS!</h2>

  <div class="form-group">
   <div class="col-sm-12">
    <p>Columns</p>
    <div ng-repeat="c in all_columns">
        <label>
            <input type="checkbox" ng-model="c.checked"> {{ c.title }}
        </label>
    </div>
 </div>
 </div>

<table class="table table-striped">
 <tr>
     <th ng-repeat="c in ordered_columns">{{ c.title }}
     </th>
 </tr>
 <tbody>
 <tr ng-repeat="d in data">
    <td ng-repeat="c in ordered_columns">{{ d[c.title] }}</td>
 </tr>
</tbody>
</table>

</body>




</html>
    
08.04.2016 / 13:44