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