如何使用angularJS
访问header指令中的搜索模型 <div header showprofile="false" >
<div class="searchView col-xs-12">
<input type="text" placeholder="Search" ng-model="search" />
</div>
</div>
<div class="divtop">
<!-- <input type="text" placeholder="Search" ng-model="search" /> -->
<div class="it-content col-xs-12 col-sm-12 col-md-12">
<div ng-repeat="it in itBatch.its | filter: search" class="visit-card">
</div>
</div>
</div>
答案 0 :(得分:1)
您可以将模型传递给指令 -
<div header showprofile="false" search="search">
<div class="searchView col-xs-12">
<input type="text" placeholder="Search" ng-model="search" />
</div>
</div>
更新您的指令以接受它
.directive('header', function() {
function link(scope, element, attrs) {
scope.$watch(attrs.search, function(value) {
console.log(value);
});
}
return {
restrict: 'EA',
scope: {
showprofile: '=',
search: '=',
},
link: link
};
});
<强>更新强> 这是fiddle。
希望有所帮助。