I am trying to make auto-complete, for this I am using tags-input. Directive name is my-directive, Inside controller I am trying to call selectUser
function, but it is not working.
In auto-complete, you have to type 4 letters, like: john, then I will show options..
View
<body ng-app="myApp" ng-controller="appCtrl">
<my-directive apipoint="customerApi" modeldisplay="tags.selected" ng-model="tags.selected" change="selectUser(tags.selected)"></my-directive>
</body>
Controller
app.controller("appCtrl", function($scope){
$scope.tags = {};
$scope.tags.selected = [];
$scope.customerApi = ['tags.json'];
$scope.selectUser = function(foo) {
$scope.aux = foo;
alert();
};
});
Directive
app.directive("myDirective", ['$http',function($http){
return {
restrict: "E",
template : 'Here Use tag-input: <tags-input ng-model="modeldisplay"'+
'ng-change="change(modeldisplay)">'+
'<auto-complete source="loadTags($query)"></auto-complete>'+
'</tags-input>',
require: 'ngModel',
scope : {
modeldisplay: "=",
apipoint: "="
},
link : function(scope, element, attrs, ctrl){
scope.loadTags = function(query) {
return $http.get(scope.apipoint[0]);
};
scope.change = function(item){
ctrl.$setViewValue(item);
}
}
};
}]);
**DEMO/Now Working **
One more thing Is my approach I right?, Reason Behind is that, In Angularjs View, I want to use auto-complete directive oneline, I want to make it as generic approach...