1
我試圖在一個新的指令中實現一些引導類型的自定義函數。 這樣做,我需要嵌入原Typeahed指令進入礦井,通過它,我的參數:在另一個指令中嵌入AngularJS指令
這是原來的指令:
<div class="typeahead typeahead-lookup">
<input ng-model="vm.myModel"
uib-typeahead="item as item.Formatted for item in vm.refreshSearch($viewValue)"
typeahead-wait-ms="1000"
typeahead-min-length="1"
typeahead-editable="false"
placeholder="SEARCH..."
type="text"
class="form-control">
</div>
這是我的自定義指令:
<select-lookup model="vm.myModel"
items="item as item.Formatted for item in vm.refreshSearch($viewValue)"
</select-lookup>
這就是我想要實現它的方式:
function selectLookup($compile) {
return {
restrict: 'E',
scope: {
model: "=",
items: "@"
},
compile: function(element, attrs) {
return function(scope, element, attrs) {
var template = '<div class="typeahead typeahead-lookup">' +
'<input ng-model="model"' +
'uib-typeahead="{{items}}"' +
'typeahead-wait-ms="1000"' +
'typeahead-min-length="1"' +
'typeahead-editable="false"' +
'placeholder="SEARCH..."' +
'type="text"' +
'class="form-control">' +
'</div>';
element.html(template);
$compile(element.contents())(scope);
};
}
};
}
I會遇到問題,從我的指令傳遞參數到原始的Typeahead指令,特別是「項目」。 我得到這個錯誤:Expected typeahead specification in form of "_modelValue_ (as _label_)? for _item_ in _collection_" but got "{{items}}"
。
有人可以幫我解決這個問題嗎?
謝謝你ChrisY ...我試過你的解決方案,但它似乎不起作用。我在這裏創建了一個plunk:http://plnkr.co/edit/IIcc3e7uE9FWDMzFPUqv?p=preview – wizzy
'for in'語法用指令的範圍進行評估,並且沒有可用的狀態。更新了運動員:http://plnkr.co/edit/3WowFCMa7zF8JQPlw498?p=preview – ChrisY
非常感謝! – wizzy