我正在尝试从控制器动态添加自定义指令。为了添加指令,我做了以下事情。
app.controller("someCtrl",["$scope","$compile",function($scope,$compile) {
$scope.create = function() {
angular.element(#idx).append($compile("<custom-directive></custom-directive>)($scope));
}
}]);
自定义指令的模板如下:-
<div>
<input type = "text" ng-model="search"/>
<div ng-repeat = items in itemContainer | filter:search>
<!--doing something-->
</div>
</div>
以上只是一个简化的示例,仅用于演示目的。
因此它成功地在 DOM 中添加指令并在 ng-repeat 中执行所有功能,但我无法在文本框中输入任何内容,因此无法通过用户输入过滤结果。
请帮我解决这个问题。我仍在学习 AngularJS 的概念,所以这也可能是一个天真的错误。
编辑我也尝试过添加
<input type = "text" ng-model ="search"/>
通过这样做,我可以在模板内输入输入框,但这不是在 ng-repeat 中过滤“搜索”的结果。