Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

angularjs - ng-model not binding with ng-options selection


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

1 Answer

0 votes
by (71.8m points)

I managed to reproduce your issue and also to solve it.

You need to replace your ng-if with ng-show like so:

<div class="modal-footer"></div>
        <nav class="navbar navbar-expand">
            <ul class="navbar-nav ml-auto">
                <li class="nav-item mx-2" id="sizesOptions"
                    ng-show="selectedModalItem.hasVariant">Options:
                    <select ng-model="chosenVariant"
                            ng-options="variant for variant in selectedModalItem.variants">
                    </select>
                </li>
                <li class="nav-item mx-2"><b>${{selectedModalItem.itemPrice}}</b>USD</li>
                <li class="nav-item mx-2">
                  <a type="button"
                     class="fas fa-shopping-cart navTextPink fa-2x"
                     ng-click="addToCart()">
                  </a>
                </li>
            </ul>

        </nav>

ng-if will remove elements from the DOM, this way you can't bind an unexisting element. This problem is solved using ng-show.

I recommend to explore a bit about the differences between the two


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...