Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

javascript - AngularJS: ng-selected doesn't show selected value


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From the Docs:

Note: ngSelected does not interact with the select and ngModel directives, it only sets the selected attribute on the element. If you are using ngModel on the select, you should not use ngSelected on the options, as ngModel will set the select value and selected options.

— AngularJS ng-selected Directive API Reference

The ng-value directive is in the wrong place:

<md-input-container flex>
    <label>Anno selezione</label>
    <md-select name="annoSelect" ng-model="vm.anno_attuale"
               ?n?g?-?v?a?l?u?e?=?"?v?m?.?p?r?o?g?e?t?t?o?.?p?p?r?s?[?$?i?n?d?e?x?]?.?a?n?n?o?"?                 
               ?n?g?-?s?e?l?e?c?t?e?d?=?"?i?t?e?m?.?s?e?l?e?c?t?e?d?"? ?  >
         <md-option ng-repeat="item in vm.progetto.pprs" 
                    ng-value="item.anno">
           ?{?{?v?m?.?p?r?o?g?e?t?t?o?.?p?p?r?s?[?$?i?n?d?e?x?]?.?a?n?n?o?}?}?
           {{item.anno}}
         </md-option>
    </md-select> 
</md-input-container>

For more information, see Using ngValue to bind the model to an array of objects


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...