我有一个指令,该模板使用ng-include:
<ng-include src="filterTemplate"></ng-include>
模板由指令动态更改:
link: function (scope, element, attrs) {
switch (scope.type) {
case 'string':
scope.filterTemplate = "app/common/views/templates/gridHeaderString.html";
break;
case 'number':
scope.filterTemplate = "app/common/views/templates/gridHeaderNumber.html";
break;
default:
}
scope.filter = function () {
scope.filters[scope.col.field] = { value: scope.filterValue, operator: scope.filterOperator };
scope.searchMethod();
}
}
例如,gridHeaderString模板如下所示:
<input id="test" type="text" placeholder="Filter..." ng-model="filterValue" />
在指令内的filter函数中,scope.filterValue不起作用,因为在ng-include的子范围内存在filterValue。
所以在ng-include模板中,我尝试过:
ng-model="$parent.filterValue"
但仍然无效。
如何将ng-include中的模型绑定到指令的范围?
答案 0 :(得分:0)
$ parent.filterValue是要走的路。