2

テンプレートが 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" />

ディレクティブ内のフィルター関数では、filterValue が ng-include の子スコープに存在するため、scope.filterValue は機能しません。

したがって、ng-include テンプレートでは、次のことを試みました。

ng-model="$parent.filterValue" 

しかし、それでもうまくいきません。

ng-include 内のモデルをディレクティブのスコープにバインドするにはどうすればよいですか?

4

1 に答える 1