Erstellen der angular-js-Anweisung, die ng-model aktualisiert

Ich versuche, erstellen Sie eine Richtlinie, die umschließt die twitter typeahead-plugin. Was ich habe, so weit ist:

HTML:

<input ng-twitter-typeahead type="text" ng-model="participant" data="exampleData" />
{{ participant }}

Möchte ich den Wert für "Teilnehmer" aktualisiert werden, wenn ich wählen Sie etwas auf dem typeahead. Das typeahead bei einem selbst funktioniert einwandfrei, aber ich kann Sie nicht erfassen Sie den ausgewählten Wert. Unten ist die javascript:

var app = angular.module('myApp', [])
app.directive('ngTwitterTypeahead', function () {
  return {
    restrict: 'EA',
    scope: {
      data: '='
    },
    link: function ($scope, $element, $attrs) {
      $element.typeahead($scope.data);

      $element.bind('typeahead:selected', function(obj, datum) {        
         //I really don't know how to do this part
         //the variable 'datum' is what I want to be passed to ng-model
         //I tried things like:
            //Including the ngModelController and typing:
            //ngModel.$setViewValue(datum)
            //but that didn't work.
     }
  };
});

Ich bin natürlich fehlt etwas grundlegendes, wenn es um AngularJS. Jede Hilfe wäre sehr geschätzt werden!

* * EDIT

Fand ich die Lösung. Ich bin manchmal ratlos:

angular.module('siyfion.ngTypeahead', [])
  .directive('ngTypeahead', function () {
    return {
    restrict: 'C',
    scope: {
      datasets: '=',
  ngModel: '='
    },
    link: function ($scope, $element, $attrs) {
      $element.typeahead($scope.datasets);      

      $element.bind('typeahead:selected', function(obj, datum) {        
    $scope.$apply(function() {
     $scope.ngModel = datum;
    });
  })            
    }
  };
});

InformationsquelleAutor der Frage user2205763 | 2013-08-21

Schreibe einen Kommentar