0
我们有要求在用户输入“@”时显示下拉菜单。如何查找何时在textarea中输入特定字符
我打算有一个指令如下:
app.controller('MainCtrl', function($scope) {
$scope.values = ['@'];
$scope.valuesEntered = false;
});
app.directive('identifier', function ($parse) {
return {
scope: {
values: '=values'
},
link: function (scope, elm, attrs) {
elm.bind('keypress', function(e){
var char = String.fromCharCode(e.which||e.charCode||e.keyCode), matches = [];
angular.forEach(scope.values, function(value, key){
if(char === value) matches.push(char);
}, matches);
if(matches.length !== 0){
$scope.valuesEntered = true;
}
});
}
}
});
请问这个行吗?
作为参考,你可以在这里看看:https://github.com/fraserxu/ng-textcomplete – 2014-12-02 05:55:10