首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在md-chip外单击后重新聚焦

在md-chip外单击后重新聚焦
EN

Stack Overflow用户
提问于 2017-06-22 00:41:00
回答 1查看 470关注 0票数 0

在将Angular材质从版本1.1.1升级到1.1.4之后,md-chip不能像以前那样工作。

在条目中键入字符串,然后单击outside,焦点将返回到输入。

我不希望这种情况发生。

使用角度材质1.1.1:

https://youtu.be/LD2CxbuMxJg

使用角度材质1.1.4:

https://youtu.be/dG1kKvU1Y0s

有人能帮帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2017-06-23 00:57:13

mdChipsCtrl中,有一个名为shouldFocusLastChip的布尔变量,负责将焦点返回到条目。

我通过使用以下指令更改此变量的值来覆盖该函数:

代码语言:javascript
复制
angular.module('myApp').directive('mdChips', function () {
  return {                                                                   
    restrict: 'E',                                                          
    require: 'mdChips', // Extends the original mdChips directive           
    link: function (scope, element, attributes, mdChipsCtrl) {              
      mdChipsCtrl.appendChip = function (newChip) {
        // Set to FALSE                                  
        this.shouldFocusLastChip = false;                                                                    

        if (this.useTransformChip && this.transformChip) {                  
          var transformedChip = this.transformChip({'$chip': newChip});     

          // Check to make sure the chip is defined before assigning it, otherwise, we'll just assume
          // they want the string version.                                  
          if (angular.isDefined(transformedChip)) {                         
            newChip = transformedChip;                                      
          }                                                                 
        }                                                                   

        // If items contains an identical object to newChip, do not append  
        if (angular.isObject(newChip)){                                     
          var identical = this.items.some(function(item){                   
            return angular.equals(newChip, item);                           
          });                                                               
          if (identical) return;                                            
        }                                                                   

        // Check for a null (but not undefined), or existing chip and cancel appending
        if (newChip === null || this.items.indexOf(newChip) + 1) return;    

        // Append the new chip onto our list                                
        var length = this.items.push(newChip);                              
        var index = length - 1;                                             

        // Update model validation                                          
        this.ngModelCtrl.$setDirty();                                       
        this.validateModel();                                               

        // If they provide the md-on-add attribute, notify them of the chip addition
        if (this.useOnAdd && this.onAdd) {                                  
          this.onAdd({ '$chip': newChip, '$index': index });                
        }                                                                   
      };                                                                    
    }                                                                       
};
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44681787

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档