【问题标题】:Angular UI Drop down scope variable updated from directive does not update the scope从指令更新的角度 UI 下拉范围变量不会更新范围
【发布时间】:2016-02-03 21:44:49
【问题描述】:

我编写了一个指令,该指令根据按下的键更新范围变量。该代码对我来说工作正常,但变量不会更新,直到焦点重新放在下拉菜单上或拉出。下面是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];
            }
          }
        });
     }
   }
 })

【问题讨论】:

  • 请重现您的问题,使用 plunker 进行演示。
  • 我不知道为什么它不更新范围但是如果它更新了按钮内的值即使指令更新相同也不会改变。

标签: angularjs angularjs-directive angular-ui-bootstrap


【解决方案1】:

尝试 element.on('keypress') 代替 keyup

【讨论】:

  • 我可以知道将其标记为无用的原因吗?是不是和问题有关?
猜你喜欢
  • 2017-09-28
  • 1970-01-01
  • 2015-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-16
  • 1970-01-01
相关资源
最近更新 更多