Guest User

Untitled

a guest
Jan 16th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. <form ng-submit="addAssignment(assignName)">
  2. <div class="input-append">
  3. <input type="text" placeholder="Type a name" ng-model="assignName" ng-change="dostuff()" data-provide="typeahead" data-source="{{ teamNames }}">
  4. <button class="btn" type="submit">Add</button>
  5. </div>
  6. </form>
  7.  
  8. $scope.addAssignment = function(name) {
  9. alert(name);
  10. return;
  11. }
  12.  
  13. angular.module('storageApp', []).directive('typeahead', function () {
  14. return {
  15. restrict:'E',
  16. replace:true,
  17. scope:{
  18. model:'=',
  19. source:'&'
  20. },
  21. template:'<input type="text" ng-model="model"/>',
  22. link:function (scope, element, attrs) {
  23. console.log(scope.source);
  24. $(element).typeahead({
  25. source:scope.source,
  26. updater:function (item) {
  27. scope.$apply(read(item));
  28. return item;
  29. }
  30. });
  31.  
  32. function read(value) {
  33. scope.model = value;
  34. }
  35. } // end link function
  36. }; // end return
  37. }); // end angular function
  38.  
  39. <typeahead id="addSupplier" model="addSupplier" placeholder="Skriv inn leverandør" class="typeahead" source="getSuppliers()" ></typeahead>
Add Comment
Please, Sign In to add comment