2017-06-21 21 views
0

将角度材料从版本1.1.1升级到1.1.4后,md芯片不能像以前那样工作。单击外部md-chips后重新聚焦

在条目中键入一个字符串,然后单击外部,焦点返回到输入。

我不希望发生这种情况。

具有角材料1.1.1:

https://youtu.be/LD2CxbuMxJg

具有角材料1.1.4:

https://youtu.be/dG1kKvU1Y0s

任何人可以帮助我,好吗?

+0

我不能够重新产生此。你使用的是什么浏览器? –

+0

[Angular Material 1.1.4]的实例(https://fiddle.jshell.net/nxvp1mdu/3/)和[Angular Material 1.1.1](https://fiddle.jshell.net/c1osj4p7/2/ ) –

回答

0

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

我用下面的命令改变这个变量的值覆盖功能:

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 });     
     }                 
     };                  
    }                  
};