2015-11-06 108 views
0

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

这是我的代码`

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

请,为什么不是这方面的工作?!?!

+2

你的小提琴作品对我来说 – garethb

+0

http://jsfiddle.net/8e9x505d/是不是? – Errorpro

+0

它也适用于我:D –

回答

1

你在另一个控制器中用不同的名字声明了你的函数,所以它在你的jsfiddle例子中不能像预期的那样工作。请使用角度控制器而不是简单的功能。例如see this

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