我无法从我的自定义指令中调用/触发uib-typeahead函数

时间:2019-05-24 12:23:37

标签: angularjs angularjs-directive angularjs-scope

我无法通过自定义指令调用/触发uib-typeahead函数

我已经尝试过这种解决方案How to access $modelValue and $viewValue from inside custom directives?,但无法成功。

就像在动态生成的HTML /模板中使用uib-typeahead一样,在我的情况下,它不起作用。不确定这是我的问题。提供以下链接。 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
   };
}

我的模板返回uib-tyepahead的html

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函数正在从指令中触发。试图将范围也传递给模板。仍然无法成功

0 个答案:

没有答案
相关问题