Multiple ng-models on one input field?

前端 未结 2 1943

I have a form, and a list of items. I used ng-model=\"searchFor\" to filter out the list of items appropriately (this part is working fine), but I also want to \"s

相关标签:
2条回答
  • 2021-02-02 14:21

    No, ngModel wasn't supposed to do things like this, at this point it is better to start relocating the logic from the view. For this scenario you could make use of getterSetter option:

    https://docs.angularjs.org/api/ng/directive/ngModel#binding-to-a-getter-setter

    It is hard to make substantial suggestions without seeing the code.

    0 讨论(0)
  • 2021-02-02 14:34

    Try using ng-change event to capture model value and assign it to other input element with its own ng-model.

    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    
    <div ng-app>
      <input type="text" ng-model="input" ng-change="input1=input;input2=input; " />
      <input type="hidden" ng-model="input1" />
      <input type="hidden" ng-model="input2" />
      <br>Model
      <br>{{input | uppercase}}
      <br>Model 1
      <br>{{input1 | uppercase}}
      <br>Model 2
      <br>{{input2 | uppercase}}
    </div>

    0 讨论(0)
提交回复
热议问题