在ng-repeat中绑定ng-model

时间:2015-12-28 20:49:15

标签: javascript angularjs

我正在尝试将$ index绑定到ng-model上,这样当我将它发送回控制器时,我可以在console.log中找到它的值。

我之所以选择使用ngForm是因为我读到了为了在动态表单创建时绑定数据,应该有子表单以便外部spyOn(game,'compChoice').and.callFake(function(){ game.opponentChoice = "Rock"; return "Rock"; }); 可以验证。如果我错了,请纠正我。

在该部分中,我有一个按钮,显示有关现场的信息(当前人员,最大职业和完整百分比)。这似乎与$ index设置和检查工作正常(虽然我不确定这是否会影响$ index,这可能会影响表单的$ index)。

当我调用console.log($ scope.asdf)= Object {location:10}时的输出,但是所需的输出是“Object {location:[从0-11开始,因为我在places数组中有11个项目] }。

在HTML中:

<form>

在控制器中: app.controller('StudySpaces',['$ http','$ scope',函数($ http,$ scope){

<div id="page-wrapper" ng-show="loggedin" ng-controller="StudySpaces">
<form location="locationForm" ng-submit="submitLocation()" novalidate>
    <!-- Content -->
    <div class="content" ng-repeat="(i, place) in places track by $index | limitTo: 8:0">
        <section>
            ...
            <a class="button small" ng-click="selectClicked($index)" style="margin-bottom:20px; padding: 0px 20px;">View/Report Space</a>
            <!-- To report how many people there -->

            <section class="row" ng-show="isClicked($index)" style="margin-bottom:15px;">

                <div class="4u 12u(narrower)">
                    <section>
                        <header>
                            <h3>Current people</h3>
                            {{ place[1] }} people
                        </header>
                    </section>
                </div>
                <div class="4u 12u(narrower)">
                    <section>
                        <header>
                            <h3>Max Occupancy</h3>
                            {{ place[2] }} people
                        </header>
                    </section>
                </div>
                ...

                <ng-form>
                    <input type="text" name="asdf.location" ng-model="asdf.location" ng-init="asdf.location = $index" style="display:none;">
                        <button type="submit" class="btn btn-primary">I'm studying in {{place[0]}}!</button>
                </ng-form>
            </section> <!-- End of .row -->

         </section>
     </div> <!--End of .content, ngRepeat -->
</form>
</div>

0 个答案:

没有答案
相关问题