我想从我的视图中调用一个函数
<table style="width:100%">
<thead>
<tr>
<td>Name</td>
<td>Class Name</td>
<td>UserName</td>
<td>Start Date</td>
<td>End Date</td>
</tr>
</thead>
<tr ng-repeat="student in students" ng-click="getStudent(student)">
<td>{{student.studentName}}</td>
<td>{{student.className}}</td>
<td>{{userName(student.userId)}}</td>
<td>{{student.startDate}}</td>
<td>{{student.endDate}}</td>
</tr>
</table>
我将从JSON对象获取用户ID, 我想通过在控制器中使用具有以下功能的用户ID来获取学生的姓名
angular.module('studentApp.controllers').
controller('StudentController', ['$scope', 'InitialDataModel',
function ($scope, InitialDataModel) {
$scope.userName = function (id) {
var userObject = {};
userObject = _.findWhere(InitialDataModel.getUserObject, { "userId": id });
return userObject.userName;
}
}
])
但我收到错误
错误:[$ interpolate:interr]
无法插入{{userName.getUserNameByUserId(student.userId)}}
TypeError:Object function(n){return n instanceof w?n:this instanceof w?(this._wrapped = n,void 0):new w(n)}没有方法'findWhere'
如何删除此错误? 我是以正确的方式做到的吗?