简体   繁体   English

Angular ng-model语法不起作用

[英]Angular ng-model Syntax not working

First, I've been trying to replicate this excerpt from jsfiddle: http://jsfiddle.net/PQvQ2/1245/ and whenever I attempt to add in the ng-model=selection.ids[catagory.id] in my code, it throws an error that Va(...) is undefined. 首先,我一直在尝试从jsfiddle复制以下摘录: http : //jsfiddle.net/PQvQ2/1245/,并且每当我尝试在代码中添加ng-model = selection.ids [catagory.id]时,会引发错误,指出Va(...)未定义。

This is my code ` 这是我的代码

<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>`

This is driving me nuts on why this isn't working. 这让我发疯了为什么不起作用。 The controller is placed within a template and its passed in the scope. 控制器放置在模板中,并在范围内传递。

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

    };  

I simply want the stupid data inside checkboxData to look like the following: 我只是希望checkboxData中的愚蠢数据看起来像下面这样:

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

PLEASE, why isn't this working?!?! 请为什么这不起作用?!?!

You declared your function inside another controller with different name, so it doesn't work as expected in your jsfiddle example. 您在另一个具有不同名称的控制器中声明了函数,因此它无法按jsfiddle示例中的预期运行。 Please use angular controllers instead of simple function. 请使用角度控制器代替简单的功能。 For example see this 例如看这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM