我有这样的代码:
$scope.educations = [];
console.log($scope.educations.length); //works!,shows 0.
$scope.addEducation = function () {
if ($scope.educations.length < 3) { // Error
...
}
addEducation():它向UI添加了一个表单,并且我在removeEducations()中再次使用educations数组,从UI中删除了表单。
当我调用addEducation函数时错误是
TypeError: Cannot read property 'length' of undefined
为什么会这样?请帮助 (顺便说一下昨天工作正常)