Angular ng模型语法不起作用

Angular ng-model Syntax not working

本文关键字:不起作用 语法 模型 ng Angular      更新时间:2023-09-26

首先,我一直在尝试从jsfiddle中复制这段摘录:http://jsfiddle.net/PQvQ2/1245/每当我试图在代码中添加ng model=selection.ids[catagory.id]时,它就会抛出一个错误,即Va(…)未定义。

这是我的代码`

<form ng-controller="formController">
<div class="form-group">
    <tr ng-repeat="table in districtArray" id="rowId-{{table.schoolId}}" class="unselected-row">    
        <td>
        <label class="table-center-align table-checkbox-label box-unchecked" for="{{table.schoolId}}">
            <input class="table-checkbox box-unchecked" type="checkbox" ng-model="checkboxData.Id[table.schoolId]" id="{{table.schoolId}}">
            <span ng-click="updateSelection(table.schoolId)"></span>
        </label>
        </td>
    </tr>
</div>
</form>`

这让我抓狂,为什么这不起作用。控制器被放置在模板中,并在作用域中传递。

app.controller('distDashController', function($scope,$http,$timeout,$routeParams,adminDataCache) {
....
    function formController($scope){
        $scope.checkboxData.Id=$scope.table.schoolId;
        $scope.checkboxData.checked = checked;
    };  

我只是想让checkboxData中的愚蠢数据看起来如下:

{ "table.schoolId": boolean value, "table.schoolId": boolean value }

拜托,为什么不起作用?!?!

您在另一个具有不同名称的控制器中声明了您的函数,因此它在jsfiddle示例中无法正常工作。请使用角度控制器,而不是简单的功能。例如,请参阅此

app.controller('formController', function ($scope) {
    // your code
}