我正在尝试获取日期值。每当未选中该复选框且日期选择器不可见时,我都会收到错误消息:“无法读取未定义的属性'NTLI'”。如果选中该复选框并且日期选择器可见,则一切正常
<md-checkbox ng-model="user.NTLI" layout="row" ng-disabled="userForm.$invalid">
NTLI
</md-checkbox>
<div ng-show="user.NTLI">
<fieldset class="standard">
<legend>NTLI</legend>
<md-input-container>
<label>Efective date</label>
<md-datepicker ng-model="user.efectiveDateNTLI"></md-datepicker>
</md-input-container>
</fieldset>
</div>
var efDate = '';
if ($scope.user.NTLI != undefined)
{
efDate = $scope.user.efectiveDateNTLI
}
最佳答案
您需要由用户定义,
$scope.user ={};
if ($scope.user.NTLI != undefined)
{
efDate = $scope.user.efectiveDateNTLI
}