我是 angular js 的新手,我正面临这个问题(也许是一个简单的问题,但作为一个初学者,我不知道为什么会这样)。当我尝试为模型的 $scope 分配一些值时,我总是收到以下错误。其中之一如下。
HTML代码,
<input type="text" id="StartDate" class="col-sm-2" ng-model="project.StartDate" />
Angular 函数代码,
function DateUpdate($scope) {
debugger;
$scope.project.StartDate = new Date().toISOString().split("T")[0];
}
DateUpdate();
我收到类似这样的错误
TypeError: Unable to get property 'project' of undefined or null reference
感谢您的帮助,因为我在很多地方都遇到了这个错误。
最佳答案
删除 DateUpdate
函数参数 $scope
杀死现有 $scope
的存在,$scope
变为undefined
内部函数
function DateUpdate() { //<-- remove `$scope` which isn't required at all.
关于javascript - 类型错误 : Unable to get property 'project' of undefined or null reference,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43832172/