Wijmo 5 - Menu Directive

HTML

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdn.grapecity.com/wijmo/5.latest/styles/wijmo.min.css">
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.min.js"></script>
<script src="https://cdn.grapecity.com/wijmo/5.latest/controls/wijmo.input.min.js"></script>
<script src="https://cdn.grapecity.com/wijmo/5.latest/interop/angular/wijmo.angular.min.js"></script>
<!-- mark this as an Angular application and give it a controller -->
<div ng-app="app" ng-controller="appCtrl" class="container">
    
<h1>Wijmo 5 Menus</h1>

    <p>Using the menu as a value picker:</p>
    <wj-menu header="Tax" value="tax">
        <wj-menu-item value="0">Exempt</wj-menu-item>
        <wj-menu-item value=".05">5%</wj-menu-item>
        <wj-menu-item value=".085">8.5%</wj-menu-item>
        <wj-menu-item value=".09">9%</wj-menu-item>
        <wj-menu-item value=".1">10%</wj-menu-item>
        <wj-menu-item value=".12">12%</wj-menu-item>
        <wj-menu-item value=".15">15%</wj-menu-item>
    </wj-menu>

    <p>Populating a menu with commands: value is <b>{{theValue}}</b></p>
    <wj-menu header="Select Increment">
        <wj-menu-item cmd="changeValueCommand" cmd-param="50">Increment by 50</wj-menu-item>
        <wj-menu-item cmd="changeValueCommand" cmd-param="10">Increment by 10</wj-menu-item>
        <wj-menu-item cmd="changeValueCommand" cmd-param="5">Increment by 5</wj-menu-item>
        <wj-menu-separator></wj-menu-separator>
        <wj-menu-item cmd="changeValueCommand" cmd-param="-5">Decrement by 5</wj-menu-item>
        <wj-menu-item cmd="changeValueCommand" cmd-param="-10">Decrement by 10</wj-menu-item>
        <wj-menu-item cmd="changeValueCommand" cmd-param="-50">Decrement by 50</wj-menu-item>
        <wj-menu-separator></wj-menu-separator>
        <wj-menu-item cmd="changeValueCommand"><b>Reset</b></wj-menu-item>
    </wj-menu>
    
    <p></p>
    
   ...

CSS

.menuTip {
    font-size: 75%;
    font-style: italic;
    opacity: .6;
}

JavaScript

// define app, include Wijmo 5 directives
var app = angular.module('app', ['wj']);

// controller
app.controller('appCtrl', function ($scope) {

    // variable bound to the value picker menu
    $scope.tax = 0;
    
    // value handled by the command menu
    $scope.theValue = 1;
    $scope.changeValueCommand = {
        executeCommand: function (parm) {
            if (wijmo.isNumber(parm)) {
                $scope.theValue += parm;
            } else {
                $scope.theValue = 1; // reset
            }
            $scope.$apply('theValue');
        },
        canExecuteCommand: function (parm) {
            if (wijmo.isNumber(parm)) {
                var val = $scope.theValue + parm;
                return val >= 0 && val <= 100;
            }
            return true;
        }
    }
    
    // handle menu clicks: this method gets invoked when the menu's itemClicked event fires
    $scope.menuItemClicked = function (sender, args) {
        var menu = sender;
        alert('Thanks for selecting option ' + menu.selectedIndex + ' from menu **' + menu.header + '**!');
    }

});