Setting the selected item in angularJS select directive

后端 未结 4 1458
既然无缘
既然无缘 2021-02-05 07:04

I have a problem with setting the selected item in angular\'s select directive. I don\'t know if this is a bug or a conscious design from the designers of angular. It sure makes

4条回答
  •  梦如初夏
    2021-02-05 07:36

    I came accross the same problem. My options and the modeled data both came from separate API calls.

    Instead of adding a layer of indirection by using ng-model on the object keys, I ended up writing a simple directive that uses a "proxy" variable.

    
    

    becomes

    
    

    Using a $watch on customer.city and customer_cityProxy, I get the expected behaviour.

    There are still a few drawbacks, on being that it only works if the keys are disjoints.

    Code is available here: https://github.com/gosusnp/options-proxy

提交回复
热议问题