miuosh
miuosh

Reputation: 906

md-autocomplete Angular 1.x - bind data from parent controller

I have a problem: how to bind properties from parent controller? When md-selected-item and md-search-text are properties from AddTaskController (i.e. at.task.project), autocomplete works fine (return matched elements). When I try to bind data from parent - md-items | filter:edc.task.project - doesn't work properly (filter return all elements instead of matched items) http://plnkr.co/edit/ZCIU5gNwWfWdIOnz0ykb

<div ng-controller="EditTaskDialogController as edc">        
      <!-- autocomplete fields -->
          <div layout="row" ng-controller="AddTaskController as at">
            <!-- project autocomplete -->
            <div >
              <md-autocomplete required md-no-asterisk
                              md-input-name="project"
                              md-selected-item="edc.task.project"
                              md-search-text-change="at.searchProjectChange(edc.task.project)"
                              md-search-text="edc.task.project"
                              md-selected-item-change="at.selectedProjectChange(item)"
                              md-items="item in at.profile.projects | filter:edc.task.project"
                              md-item-text="item"
                              md-min-length="0"
                              md-input-minlength="0"
                              md-floating-label="Projekt...">
                          <md-item-template>
                              <span md-highlight-text="edc.task.project" md-highlight-flags="^i">{{item}}</span>
                          </md-item-template>
                          <div ng-messages="editTaskForm.project.$error" role="alert">
                              <div ng-message="required">Pole nie może być puste.</div>
                          </div>
              </md-autocomplete>

            </div>
    </div>

Upvotes: 0

Views: 349

Answers (1)

kuhnroyal
kuhnroyal

Reputation: 7553

It works, you are just overwriting it with this: md-search-text="edc.task.project". This is a reference and as soon as you clear the input field it will be set to undefined or empty. As a result your filter will not filter.

The second problem is because you set a md-selected-item. As soon as one is set, the input needs to be cleared before autocomplete will search again.

Upvotes: 1

Related Questions