angular-option-tree

A directive to use jquery-option-tree with AngularJS.

Getting Started

  1. Install with bower: bower install --save angular-option-tree
  2. Include angular-option-tree.js.
  3. Add option-tree to you app modules.
  4. Use the option-tree directive.
If you hate proper package management, you can also directly download angular-option-tree.js or angular-option-tree.min.js.

Usage

Basic
<form class="form-horizontal" role="form" ng-controller="Demo1Ctrl">
  <input option-tree="tree_data" option-tree-class="form-control">
</form>
angular.module('optionTreeApp', ['option-tree']).
    controller('Demo1Ctrl', function ($scope) {
      $scope.tree_data = {
        'Option 1': {
          'Suboption': 200
        },
        'Option 2': {
          'Suboption 2': {
            'Subsub 1': 201,
            'Subsub 2': 202
          },
          'Suboption 3': {
            'Subsub 3': 203,
            'Subsub 4': 204,
            'Subsub 5': 205
          }
        }
      };
    });
Preselected Options
<form class="form-horizontal" role="form" ng-controller="Demo2Ctrl">
  <input option-tree="tree_data" option-tree-class="form-control" value="203">
</form>
Change Option Data Dynamically

<form class="form-horizontal" role="form" ng-controller="Demo3Ctrl">
  <input option-tree="tree_data" option-tree-class="form-control">
  <button> type="button" ng-click="change_tree_data()">Change</button>
</form>
angular.module('optionTreeApp', ['option-tree']).
    controller('Demo3Ctrl', function ($scope) {
      $scope.tree_data = {
        'Option 1': {
          'Suboption': 200
        },
        'Option 2': {
          'Suboption 2': {
            'Subsub 1': 201,
            'Subsub 2': 202
          },
          'Suboption 3': {
            'Subsub 3': 203,
            'Subsub 4': 204,
            'Subsub 5': 205
          }
        }
      };

      $scope.change_tree_data = function() {
        $scope.tree_data = {
          'Another Option 1': {
            'Suboption': 200,
            'Suboption 3': {
              'Subsub 3': 203,
              'Subsub 4': 204,
              'Subsub 5': 205
            }
          },
          'Another Option 2': {
            'Suboption 2': {
              'Subsub 1': 201,
              'Subsub 2': 202
            }
          }
        };
      };
    });
Loading Remote Data
<form class="form-horizontal" role="form" ng-controller="Demo4Ctrl">
  <input option-tree option-tree-src="example.json" option-tree-class="form-control">
</form>

Fork me on GitHub