是否可以在 md-autocomplete 的输入中添加指令

Is it possible to add a directive to the input of a md-autocomplete

我使用一个指令来格式化我的输入。现在我还想将它与 md-autcomplete 的输入一起使用。

我认为我已经读过在一个元素上使用两个具有独立作用域的指令是不可能的。我对吗? 否则我怎样才能访问 md-autocomplete 的输入?

提前致谢

更多信息:(angular material 1.1 + angular 1.5.*)

组件来源:

.component('payeeInformation', {
       bindings: {...
  },                
  templateUrl: 'payeeInformationTemplate',

  controller:function(autocompleteService, $rootScope, $scope, $element, $compile, $document){
    var ctrl = this;
    this.genericAutocompleteSearch = autocompleteService.genericSearch;

    addDirectiveToInputOfAutomplete('#my-input');

    function addDirectiveToInputOfAutomplete(id){
      var myAutoCompleteInput = angular.element($element[0].querySelector(id));
      myAutoCompleteInput.attr("my-directive");
      $compile(myAutoCompleteInput)($scope);
  }
}

这个概念证明似乎有效 - CodePen

标记

<md-autocomplete ... md-input-id="myAutoCompleteInput">

JS - 指令

.directive('test', function () {
    return {
        restrict: 'A',
        scope: {
            text: '@text'
        },
        link:function(scope,element){
            console.log(scope.text);
        }
    };
});

JS - 控制器

$timeout(function () {
  var myAutoCompleteInput = angular.element($element[0].querySelector('#myAutoCompleteInput'));
  myAutoCompleteInput.attr("test", "test");
  myAutoCompleteInput.attr("text", "blah");
  $compile(myAutoCompleteInput)($scope);
});

在控制台中你可以看到指令中的console.log输出"blah"。需要控制器中的 $timeout 才能获取具有 id.

md-autocomplete 元素