我正在忙于接受一个教程,作为一名角度新手,并且已经达到引入Controller的地步。我的MVC视图生成以下标记:Angular为什么看不到我的控制器?
<script>
function PersonController($scope) {
$scope.persons = [
{ firstName: 'Brady', lastName: 'Kelly' },
{ firstName: 'James', lastName: 'Brown' },
{ firstName: 'Charles', lastName: 'Manson' }
];
}
</script>
<table class="table" data-ng-controller="PersonController">
<tr>
<th>
<span>Last Name</span>
</th>
<th>
<span>First Name</span>
</th>
<th></th>
</tr>
<tr data-ng-repeat="pers in persons | orderBy:'lastName'">
<td>
{{pers.lastName}}
</td>
<td>
{{pers.firstName}}
</td>
<td></td>
</tr>
</table>
当我用ng-init
指令来实例化人阵“内联”,如:工作
<table class="table" data-ng-init="persons=[....]">
该表中的数据绑定,但是当我用的是ng-controller
指令,如我上面的例子,我在Chrome的控制台得到一个错误,指出:
Error: [ng:areq] Argument 'PersonController' is not a function, got undefined
尝试添加NG-应用 – ABOS
你能不能显示完整的代码 – Kushal
同样的错误,在这里http://stackoverflow.com/questions/24929296/error-ngareq-argument-myctrl-is-not-a-function -got-undefined –