繁体   English   中英

从指令更新的Angular UI下拉范围变量不会更新范围

[英]Angular UI Drop down scope variable updated from directive does not update the scope

我写了一条指令,该指令根据所按下的键更新作用域变量。 该代码对我来说很好用,但是直到焦点重新放在下拉列表上或拉下该变量之后,变量才会更新。 以下是html和指令代码:

<button type="button" drop-select ="card.purchaseType">{{card.purchaseType}}</button>

 appModule.directive('dropSelect', function() {
   return {
     scope: {
       purchaseType:'=dropSelect'
     },
     link: function(scope, element, attrs){
       var items =["Retail Purchases","Prescription Purchases", "Retail and Prescription Purchases"];
        element.on('keyup', function(e){
          // Get the character pressed
          var stringChar = String.fromCharCode(e.keyCode), currentItem = scope.purchaseType;
          for(var itemCount = 0; itemCount < items.length; itemCount++){
            if(stringChar == items[itemCount].charAt(0) &&
              currentItem != items[itemCount]){
              scope.purchaseType = items[itemCount];
            }
          }
        });
     }
   }
 })

尝试使用element.on('keypress')而不是键盘

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM