I am trying to create an angular.js directive from James Smith tokenInput jQuery plugin: http://loopj.com/jquery-tokeninput
Here is what I still have:
antdna = angular.module('Communication', []); antdna.factory('autoCompleteService', [function() { return { getSource: function() { return [{"id":1, "name":"John Doe"}, {"id":2, "name":"Jane Smith"}]; } } }]); antdna.directive('autoComplete', function(autoCompleteService) { return { restrict: 'A', link: function(scope, elem) { elem.tokenInput(autoCompleteService.getSource(), { crossDomain:false, theme: "facebook", hintText: "Enter User Name", preventDuplicates: true }); } }; });
With the following markup:
<input type="text" name="recipient" ng-model="conversation.recipients" class="messageComposeTextField" auto-complete placeholder="To :" required />
TokenInput works fine, but the problem is that I cannot bind to the model.
{{conversation.recipients}}
is empty.
The tokenInput plugin generates its own markup using list items (ul and li). Therefore, checking the element, I get:
<ul class="token-input-list-facebook"> <li class="token-input-token-facebook"><p>John Doe</p><span class="token-input-delete-token-facebook">×</span></li><li class="token-input-input-token-facebook"><input type="text" autocomplete="off" autocapitalize="off" id="token-input-" style="outline: none; width: 30px;"><tester style="position: absolute; top: -9999px; left: -9999px; width: auto; font-size: 12px; font-family: Ubuntu, 'Ubuntu Beta', UbuntuBeta, Ubuntu, 'Bitstream Vera Sans', 'DejaVu Sans', Tahoma, sans-serif; font-weight: 400; letter-spacing: 0px; white-space: nowrap;"></tester> </li> </ul> <input type="text" name="recipient" ng-model="conversation.recipients" class="messageComposeTextField ng-pristine ng-invalid ng-invalid-required" auto-complete="" placeholder="To :" required="" style="display: none;">
Note that the generated tokenInput markup is not part of the directive. So the real question is, how can I encapsulate a jquery plugin that generates its own markup in the angularjs directive?
angularjs angularjs-directive jquery-tokeninput
Mark kenny
source share