Я не могу вызвать / вызвать функцию uib-typeahead из моей пользовательской директивы - PullRequest
0 голосов
/ 24 мая 2019

Я не могу вызвать / вызвать функцию uib-typeahead из моей пользовательской директивы

Я пробовал этот soln Как получить доступ к $ modelValue и $ viewValue из пользовательских директив? , но не удалось.

Похоже, когда мы используем uib-typeahead в динамически генерируемом HTML / шаблоне, так как в моем случае это не работает. Не уверен, что это моя проблема. Предоставление ссылки ниже. https://github.com/angular-ui/bootstrap/issues/4631

директива в ассоциированном html

<dyna-screen entityname="pis-entity" ></dyna-screen>

код контроллера идет сюда

// function I try to call from directive uib-typeahead
$scopeObj.getLocationResponseBuilder = function (input) { 

  // making a REST API call with the typeahead 'input' here.. 
  // and building the list(below code) from response which needs to be populated in uibtypeahead 


  var hoteldestlist = responseVO.searchResponses;
  var locationlist = [];

  angular.forEach(hoteldestlist, function (location) {
    var destination;
    if (location.category == 'Place') {
      destination= "(PLC)";                        
    } else if (location.category == 'City') {
      destination= "(CTY)";                    
    } else if (location.category == 'Destination') {
      destination= "(DES)";                        
    }                    

    locationlist.push({key:location.masterKey,value:location.masterValue + '('+destination+')'});

  });

  return locationlist;

}

моя директива

var link = function ($scope, element, attrs,controller) {        

  $scope.model = controller;
  $scope.viewValue = controller.$viewValue;
  debugger;
  $scope.modelValue = controller.$modelValue;
  $scope.tagName = controller.$name;
                 //.
                 //.
                 //.
  tempRenderFields = tempRenderFields + dynaInputControlFactory.getuibtypeaheadTemplate(value,$scope.viewValue,$scope); // call to factory from directive to get the template for uib-typeahead
            //.
            //.
            //.

  return {
    scope: {
      didFn: '&',
      setFn: '&',
      myDirectivedata: '&callbackFnf', // for directrive to 
      controller testing purpose            
     },
     //template: template1,
     restrict: 'E',          
     replace: 'false',
     link: link
   };
}

мой шаблон, который возвращает html для uib-tyepahead

dynaInputControlFactory.getuibtypeaheadTemplate = function (field,viewvalue,scope) {
  var uibtypeaheadTemplate =
    '<div class="form-group">' + 
    getLabelTemplate(field) +
    '<input class="form-control left" type="text" ng-model="formdata.' + 
    field.attributeID + '" ' +
    ' id="' + field.attributeID + 
    '" ng-pattern="' + 
    decodeURIComponent(field.validationRegex) + 
    '" uib-typeahead="' + 
    "state as state.value for state in scope.getLocationResponseBuilder (viewvalue)" + 
    '" autocomplete="' + "off" + 
    '" typeahead-select-on-exact="' + 
    "true" + '" typeahead-min-length="' + '3' +  '" ' +
    ' tabGroupName="' + field.tabGroupName + '" tabGroupOrderIndex="' + 
    field.tabGroupOrderIndex + '" tabName="' + field.tabName + '" ' +'" 
    isRepeatbleGroup="' + field.isRepeatbleGroup + '" ' +'" 
    masterDataConfiguration="' + field.masterDataConfiguration + '" ' +
    ' tabOrderIndex="' + field.tabOrderIndex + '" groupName="' + 
    field.groupName + '" groupOrderIndex="' + field.groupOrderIndex + '" 
    attributeLabelCaption="' + field.attributeLabelCaption + '" ' +
    ' ng-style="' + getCssClass(field) + '" ' +
    '       ng-required="' + field.isRequired + '" ng-readonly="' + 
    this.isReadOnly + '" ng-minlength="' + field.minLength +
    '" ng-maxlength="' + field.maxLength + '" ' +
    // '       placeholder="' + field.attributeHelpText + 
    '" /> ' +
    ' </div> ';
    // console.log('getTextBoxTemplate = ' + textBoxTemplate);
    debugger;
    return uibtypeaheadTemplate;

Вроде как

"state as state.value for state in scope.getLocationResponseBuilder (viewvalue)" 

не разрешается в DOM.

getLocationResponseBuilder функция запускается из директивы. Попытался передать область также в шаблон. Все еще не смог добиться успеха

...