Javascript 属性指令将行为添加到另一个指令
我使用angularjs中的事件创建完全解耦的指令。作为一个例子,我正在使用创建一个搜索指令并以这种方式实现它Javascript 属性指令将行为添加到另一个指令,javascript,angularjs,angularjs-directive,Javascript,Angularjs,Angularjs Directive,我使用angularjs中的事件创建完全解耦的指令。作为一个例子,我正在使用创建一个搜索指令并以这种方式实现它 'use strict'; angular.module('app') .directive('search', function () { return { scope: true, restrict: 'E', controller: function($rootScope) { var vm = this;
'use strict';
angular.module('app')
.directive('search', function () {
return {
scope: true,
restrict: 'E',
controller: function($rootScope) {
var vm = this;
vm.onChange = function (searchValue) {
$rootScope.$broadcast('searchbox-valuechanged', {data: searchValue});
};
},
controllerAs: 'ctrl',
bindToController: true,
templateUrl: 'search.html'
};
});
而html看起来是这样的:
<input type="search" placeholder="Search"
ng-model="ctrl.searchValue"
ng-model-options="{debounce: 100}"
ng-change="ctrl.onChange({search: ctrl.searchValue})">
在我看来,我应该能够像这样使用searchable
指令:
<list-directive items="ctrl.items" searchable by="tags,title"></list-directive>
而searchable指令应该能够遍历父指令中的项并解析列表,并且只返回属性值等于by
列表的项
更新
因此,问题是:
项
谢谢 问题是?好的,我会更新问题,抱歉
<list-directive items="ctrl.items" searchable by="tags,title"></list-directive>