2017-02-11 128 views
1

当前我正在使用非常强烈的形式,并在HTML上使用输入,textareas,datepickers等,这会使代码看起来非常难看,也很难阅读。 的事情是,我创建了返回正确的HTML元素如自定义指令:从自定义指令中调用角度UI引导指令

在HTML

<suggest-input data-ng-model="EDCtrl.headerStep.provider.identification" 
       placeholder="'Ej. 888888-8'" 
       label="'Identificador de emisor'"> 
</suggest-input> 

指令:

var suggestInput = function ($compile, $http) { 
    return { 
    restrict: 'E', 
    require: 'ngModel', 
    templateUrl: templates + '/suggestInputTemplate.tpl.html', 
    replace: true, 
    scope: { 
     model: '=ngModel', 
     label: '=label', 
     title: '=title', 
     placeholder : '=placeholder' 
    }, 
    }; 
}; 

模板

<div> 
    <label>{{ label }}</label> 
    <input class="form-control" data-ng-model="model" placeholder="{{ placeholder }}" call="functionName()"/> 
</div> 

,我在使用角度引导指令时遇到问题我的自定义指令,例如: 如何在我的自定义指令中使用这种配置调用“uib-typeahead”?

任何想法?

+0

[自定义指令中的Angular UI指令]的可能重复(https://stackoverflow.com/questions/48654008/angular-ui-directive-inside-custom-directive) – Isaac

回答

0

您可以在自己的嵌套指令中使用任何嵌套指令,在这种情况下angular-ui-boostrap指令不是特殊的。关于uib-typeahead你可以看到在angular-ui-bootstrap网站下面的例子:

<input type="text" ng-model="asyncSelected" 
    placeholder="Locations loaded via $http" 
    uib-typeahead="address for address in getLocation($viewValue)" 
    typeahead-loading="loadingLocations" 
    typeahead-no-results="noResults" class="form-control"> 

知道的唯一重要的事情是ngModel是指令本身,你可以通过link(scope, element, attrs,ngModelController)访问它。 ngModelController具有$viewValue$modelValue属性,它们表示来自外部作用域的绑定值。所以而不是 scope:{model:'=ngModel'}使用这些变量在您的指令中进行绑定。

+1

对不起,但我没有看到你在评论中告诉我什么,你能举出一个角度为1.6的例子吗? – flaalf