2017-02-13 24 views
0

我想要創建一個指令,其中當用戶在文本區域鍵入'@u'顯示用戶或'@ c'顯示國家/地區時,我想要在文本區域下方顯示選擇選項,區域根據關鍵字和給定訪問權限上下移動來選擇選項。同時用戶還可以在文本區域中輸入文本。任何人都可以在此幫助我。同時訪問文本框並選擇使用angularjs

回答

0

工作plunkr:

https://plnkr.co/edit/CCEqiupjdHyaF2MriJil?p=preview

angular.module('testApp',[]).controller('testCtrl',['$scope',function($scope){ 
    $scope.users = ['user1','user2','user3']; 
    $scope.country = ['IND','AUS','ENG']; 
}]).directive('userCountry',function(){ 
    return{ 
     scope:{ 
     users : '=users', 
     country:'=country' 
     }, 
     restrict : 'EA', 
     templateUrl:'userCountry.html', 
     controller: ['$scope',function($scope){ 
     $scope.watchStart=false 
     $scope.textareaChange = function(evt) { 
      if(evt.key === "@"){ 
      $scope.watchStart = true; 
      return; 
      } 
      if($scope.watchStart){ 
      if(evt.key === "u"){ 
       $scope.options=$scope.users; 
      }else if(evt.key === "c"){ 
       $scope.options=$scope.country; 
      }else{ 
       $scope.options=[]; 
      } 
      $scope.watchStart = false; 
      } 
     } 
     }] 
    }; 
}); 

請通過plunkr。我已經排除以下內容:選擇編程

    • 開幕的textarea的選擇字段值選擇的變化(我假設你想實現這一點) - 這可以通過利用它們各自的模型來完成
  • +0

    感謝您的回覆。我的要求是不使用鼠標我需要選擇該選項,並繼續在文本區域輸入。基於使用@的建議應該顯示和不使用鼠標的選項可以選擇或繼續打字。 –

    相關問題