I'm new in Angular and I would like to know if it's possible to bind in a directive a part of an expression ?
Currently without a directive I do this (it's working) :
<div>
<ui-select ng-model="myModel" search-enabled="false">
<ui-select-match>
<span>{{'myLabelPrefix.' + $select.selected.myLabelCode | translate}}</span>
</ui-select-match>
<ui-select-choices repeat="item in (myList | filter: $select.search) track by item.myLabelId"
position="down">
<span>{{'myLabelPrefix.' + item.myLabelCode | translate}}</span>
</ui-select-choices>
</ui-select>
</div>
What I want to do :
My template :
<div>
<ui-select ng-model="ngModel" search-enabled="false">
<ui-select-match>
<span>{{labelPrefix + $select.selected.labelCode | translate}}</span>
</ui-select-match>
<ui-select-choices repeat="item in (list | filter: $select.search) track by item.labelId" position="down">
<span>{{labelPrefix + item.labelCode | translate}}</span>
</ui-select-choices>
</ui-select>
</div>
My directive :
app.directive('selectField', function() {
return {
replace: true,
templateUrl: 'app/components/select-field/select-field-view.html',
restrict: 'E',
require : 'ngModel',
scope: {
ngModel: "=ngModel",
labelPrefix: '=',
labelId: '=',
labelCode: '=',
list: '='
},
link: function(scope, el, attr) {
console.log(attr);
}
};
});
My HTML tag :
<select-field ng-model="myModel"
label-prefix="'myLabelPrefix'"
label-id="myLabelId"
label-code="myLabelCode"
list="myList">
</select-field>
So, how to bind label-prefix, label-id, label-code and list attributes with directive attributes ?
Thanks