在我的AngularJS项目中,我有2个带input
的指令和一个文本块,默认情况下是隐藏的。我的任务是立即在事件中显示此块( var app = angular.module('app', []);
app.controller('ctrl', function($scope){
$scope.showResults = false;
$scope.show = function(){
$scope.showResults = true;
}
})
app.directive('inputDir', function(){
return {
restrict: 'E',
templateUrl: autocomplete.html,
scope: {
field: '@'
},
link: function (scope, elem, attrs) {
scope.showResults = false;
scope.selectedItem = function () {
var isSelected = angular.element(document.querySelector('li')).text();
if(isSelected.$valid && angular.isDefined(isSelected)){
scope.showResults = true;
}
}
}
}
});
中的文本将从两个指令中的自动完成中选择)。
换句话说,要检查两个指令以及是否选择了所有自动填充,请显示此块。
如何实现此功能?
<html ng-app="app">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="main.js"></script>
</head>
<body ng-controller="ctrl">
<input-dir field="field1"></input-dir>
<div class="results" ng-show="showResults">
<p>Results</p>
</div>
<input-dir field="field2"></input-dir>
</body>
</html>
----------------------------------------------------------------------
autocomplete.html
<md-autocomplete class="city" ng-disabled="isDisabled" md-no-cache="noCache" md-selected-item="selectedItem" md-search-text-change="searchTextChange(searchText)" md-search-text="searchText" md-selected-item-change="selectedItemChange(item)" md-items="item in querySearch(searchText)" md-item-text="item.display" md-min-length="0" placeholder="{{place}}">
<md-item-template >
<span md-highlight-text="searchText" md-highlight-flags="^i" >{{item.display}}</span>
</md-item-template>
</md-autocomplete>
&#13;
{{1}}&#13;
我试图从输入中获取文本并检查输入中的文本是否有效,但我的尝试没有成功