Angular ng-model语法不起作用

时间:2015-11-06 05:19:32

标签: javascript angularjs angular-ngmodel

首先,我一直试图从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 }

请问,为什么这不起作用?!?!

1 个答案:

答案 0 :(得分:1)

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

mongoDBCollectionObject.findOneAndRemove({ // -- it will delete the entire document
  _id: req.body.fieldsdata._id  // here fiedsdata is exact copy with modification  of previous data
  }, function(err, data) {
  var newFieldsData = new mongoDBCollectionObject(fieldsdata); //-- fieldsdata updated data
  newFieldsData.save(function(err, data) { // save document to that collection with updated data
    if (err) {
      console.log(err);
    } else
        res.json({
          success: true
          });
    });
  })
相关问题