Setting Initial Value for Wijmo Autocomplete

by Joel Parks

HTML

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.min.js"></script>
<link rel="stylesheet" href="http://cdn.wijmo.com/5.latest/styles/wijmo.min.css">
<script src="http://cdn.wijmo.com/5.latest/controls/wijmo.input.min.js"></script>
<script src="http://cdn.wijmo.com/5.latest/interop/angular/wijmo.angular.min.js"></script>
<div ng-app="app" ng-controller="appCtrl">
    
  <h4>Organization</h4>
  <wj-auto-complete
    items-source-function="lookupOrganizations"
    selected-value="selectedOrganization.Id"
    selected-value-path="Id"
    display-member-path="Name">
  </wj-auto-complete>
  <p>
    Selected Organization ID: <b>{{ selectedOrganization.Id }}</b>
  </p>
    
</div>

JavaScript

var app = angular.module('app', ['wj']);

app.controller('appCtrl', function ($scope) {
  
  // Mock data source
  $scope.allOrganizations = [
    { Id: 1, Name: "Acme Tools" },
    { Id: 2, Name: "Adware Solutions" },
    { Id: 3, Name: "Axis Entertainment" },
    { Id: 4, Name: "Bolivian Coffee House" }
  ];

  // How do we set an initial value?
  $scope.selectedOrganization = { Id: 3, Name: "Axis Entertainment" };

  $scope.lookupOrganizations = function (query, maxItems, callback)
  {
    callback($scope.allOrganizations);
	};
        
});