我有一个指令,它使用模板在带有相关标签和css类的表单中生成一个预先输入。
<div class="form-group" ng-class="{ 'has-success': hasSuccess(field),
'has-error' : hasError(field) }">
<label class="control-label" for="{{ field }}">
{{ label }}
</label>
<input type="text"
class="form-control"
ng-model="model"
name="{{ field }}"
id="{{ field }}"
typeahead="{{ items }}"
required>
</div>
这是使用以下标记创建的:
<fe-ta model='model.state2' label='State' items='s in states'></fe-ta>
问题是传递给items
的表达式。我得到以下异常:
Syntax Error: Token 'in' is an unexpected token at column 3 of the expression \
[s in states] starting at [in states].
我的指令在其隔离范围中将items
作为表达式&
.directive('feTa', function() {
return {
restrict: 'E',
require: ['^form', '^feForm'],
scope: {
model: '=',
label: '@',
items: '&
},
templateUrl: 'typeahead.tmpl.html',
replace: true,
link: function (scope, element, attrs, controllers) {
var feFormController = controllers[1];
scope.field = attrs.model.substring(attrs.model.indexOf('.') + 1);
scope.hasSuccess = feFormController.hasSuccess;
scope.hasError = feFormController.hasError;
}
};
});
如何将表达式传递给我的指令?
此处的Plunker:http://plnkr.co/edit/ivvJzUOxKGsAqqgzDPl0?p=preview