Icontem

File: examples/assets/tools.js

Recommend this page to a friend!
  Classes of Jean-Baptiste DEMONTE  >  Angular Google Maps Native  >  examples/assets/tools.js  >  Download  
File: examples/assets/tools.js
Role: Example script
Content type: text/plain
Description: Example script
Class: Angular Google Maps Native
Add AngularJS directives to render GoogleMaps
Author: By
Last change:
Date: 4 years ago
Size: 1,243 bytes
 

Contents

Class file image Download
angular.module('ExampleTools', [])

  .service('console', function () {
    var items = [];
    function add(item) {
      var dt = new Date(),
        h = dt.getHours(),
        m = dt.getMinutes(),
        s = dt.getSeconds(),
        t = (h < 10 ? '0' : '') + h + ':' + (m < 10 ? '0' : '') + m + ':' + (s < 10 ? '0' : '') + s;
      item.msg = '<time>' + t + '</time> ' + item.msg;
      items.push(item);
      items.splice(0, items.length - 10); // only keep last 10 entries
    }
    return {
      log: function (msg) {
        add({msg: msg, type: 'log'});
      },
      warn: function (msg) {
        add({msg: msg, type: 'warn'});
      },
      error: function (msg) {
        add({msg: msg, type: 'error'});
      },
      items: items
    };
  })

  .directive('console', function (console) {
    return {
      restrict: 'E',
      template: '<div class="console" ng-if="console.items.length">' +
      '<p ng-repeat="item in console.items track by $index" ng-bind-html="item.msg | unsafe"></p>' +
      '</div>',
      link: function (scope, element, attrs) {
        scope.console = console;
      }
    }
  })

  .filter('unsafe', function($sce) {
    return function(val) {
      return $sce.trustAsHtml(val);
    };
  })
;