Ng-click in template widget

Thank you for this hint.

For interested people, I’ve rewritten the code as follows:

JavaScript in html/js/switch-dashboard.js:

(function () {
    "use strict";

    angular
        .module("switchDashboard", [])
        .directive("switchDashboard", switchDashboard);

    switchDashboard.$inject = ["$location"];
    function switchDashboard ($location) {
        var directive = {
            restrict: "A",
            link: link
        };

        return directive;

        function link(scope, elem, attrs) {
            elem.bind("click", function () {
                $location.url("/view/" + attrs.dashboard);
            });
        }
    };
})();

In my template I use the following code:

<div class="box-content switch" oc-lazy-load="['/static/js/switch-dashboard.js']"
     ng-style="{ 'background-color': itemValue('gContactOpen') == 0 ? 'transparent' : '#C00' }">
  <div class="switch-content" switch-dashboard dashboard="Fenster">
    <widget-icon iconset="'eclipse-smarthome-classic'" icon="'contact'"
                 inline="true" size="64"
                 state="itemValue('gContactOpen') == 0 ? 'CLOSED' : 'OPEN'"></widget-icon>
    <span style="font-size: 16pt;">
      <ng-pluralize count="itemValue('gContactOpen')"
                    when="{
                          '0': 'Alles geschlossen',
                          'one': 'Ein Fenster oder eine Tür offen',
                          'other': '{} Fenster oder Türen offen'
                          }"></ng-pluralize>
    </span>
  </div>
</div>

Maybe one could write it more simple.

1 Like