I'm trying to get data from a form element and then insert a using jQuery .after() to display possible choices. My direct gets the possible matches from the form by getting a attribute called "data" that is loaded by using AngularJS. The issue now, is when I try to ng-repeat with the new inserted it doesn't list it.
'use strict';
angular
.module('autoComplete', [])
.directive('autoComplete', autoComplete);
function autoComplete($parse) {
var directive = {
restrict: 'EA',
require: '?ngModel',
link: link,
};
return directive;
function link(scope, elem, attr, ngModel) {
var modelGet = $parse(attr['ngModel']);
var modelSet = modelGet.assign;
scope.$watch(function() {
return modelGet(scope);
}, function() {
var string = modelGet(scope);
if (string != undefined && string.length > 6) {
var vm = this;
vm.data = attr.data;
vm.width = elem.outerWidth();
elem.after('<div><ul class="list-group" style="position: absolute; width: '+vm.width+'px;"><li class="list-group-item" ng-repeat="codes in vm.data track by $index">{{code}}</li></ul></div>');
console.log(vm.data); //This outputs the data just fine
}
});
}
}
Once that is placed in, the only things that is produced on the screen is {{code}}. I'm assuming I should be trying to compile this somehow in angular?