如何从指令到视图或控制器获取指令的ng-model值?

时间:2016-12-12 16:07:34

标签: angularjs angularjs-directive

JS文件(某些部分):

$scope.selectedData = null;
$http.get("http://localhost:7643/api/MemberApi/GetMembers/")
  .success(function(data) {
  $scope.datas = data;

  $scope.onSelect = function(selection) {
    $scope.selectedData = selection;
  };
})

我有一个指示: 其实我正在使用这个:http://angularscript.com/simple-autocomplete-directive-angular/

app.directive('autocomplete', ['autocomplete-keys', '$window', '$timeout', function(Keys, $window, $timeout) {
return {
    template: '<input type="text" class="autocomplete-input" placeholder="{{placeHolder}}"' +
                    'ng-class="inputClass"' +
                    'ng-model="searchTerm"' +
                    'ng-keydown="keyDown($event)"' +
                    'ng-blur="onBlur()" />' +

                '<div class="autocomplete-options-container">' +
                    '<div class="autocomplete-options-dropdown" ng-if="showOptions">' +
                        '<div class="autocomplete-option" ng-if="!hasMatches">' +
                            '<span style="color:red;">No Matches Found</span>' +
                        '</div>' +

                        '<ul class="autocomplete-options-list">' +
                            '<li class="autocomplete-option" ng-class="{selected: isOptionSelected(option)}" ' +
                                'ng-style="{width: optionWidth}"' +
                                'ng-repeat="option in matchingOptions"' +
                                'ng-mouseenter="onOptionHover(option)"' +
                                'ng-mousedown="selectOption(option)"' +
                                'ng-if="!noMatches">' +
                                '<span>{{option[displayProperty]}}</span>' +
                            '</li>' +
                        '</ul>' +
                    '</div>' +
                '</div>',
    restrict: 'E',
    scope: {
        options: '=',

我的观点:

<autocomplete options="datas" place-holder="Search MemberID..." on-select="onSelect" display-property="MemberID" input-class="form-control" clear-input="false"></autocomplete>    
<div ng-if="selectedData.Picture">
  <img src="/Images/Members/{{selectedData.Picture}}" alt="{{selectedData.MemberName}}" width="90" height="70" />
  <span>{{selectedData.MemberName}}</span>
</div>
<p class="error" ng-show="!searchTerm">Please Fill the field!</p>

如何在ng-if中查看指令的内部输入字段的“searchTerm”值?

0 个答案:

没有答案