问题在于子指令绑定到父指令,但是{{name}}
语法被ng-repeat
忽略了。那么实现这个的正确方法是什么?
HTML(主/子指令)
<compact-select
no-item-selected-text="Add a Customer"
no-item-selected-icon="fa-user"
search-placeholder="Type a customer name"
cs-model="customer"
cs-items="contacts"
>
<display-item-template>
<span>{{name}}</span>
or
<span>{{item.name}}</span>
</display-item-template>
</compact-select>
指令
angular.module('core').directive('compactSelect', [function($timeout) {
return {
templateUrl : 'modules/core/views/components/compact-select-tpl.html',
bindToController: true,
transclude: true,
scope: {
noItemSelectedText: '@',
noItemSelectedIcon: '@',
csModel: '=',
csItems: '=csItems'
},
controllerAs : 'ctrl',
controller : function($scope) {
}
};
}]).directive('displayItemTemplate', function($timeout) {
return {
require: '^compactSelect',
restrict: 'E'
}
});
指令模板(modules/core/views/components/compact-select-tpl.html)
<div class="compact-select-repeater-box" style="" >
<div ng-transclude ng-repeat="item in ctrl.csItems | filter:searchParam" class="compact-select-repeater" ng-class="ctrl.getHighlightedClass(item)" ng-click="ctrl.itemSelected(item)">
<span>{{item.name}}</span>
<span>{{item.id}}</span>
</div>
<div style="position:absolute;bottom:0">
<a href="#">+ Click here to add customer {{ctrl.message}}</a>
</div>
</div>
我能看到
<span>{{item.name}}</span>
<span>{{item.id}}</span>
被替换为
<span></span>
or
<span>{{item.name}}</span>
而不是使用
<span>{{name}}</span>
or
<span>{{item.name}}</span>
问题:如何让ng-repeat
从子指令中获取html绑定语法?或者有其他方法可以实现这一点吗?