无权访问我的控制器 Angular 中的属性.js 1.3
Don't have access to attribute in my controller Angular.js 1.3
我正在构建一个简单的表单。此表单获取生日字段。我可以选择一个日期并坚持它。但是当我重新加载页面时,我遇到了错误
Error: [ngModel:datefmt] Expected `2015-03-06T23:00:00.000Z` to be a date
我知道如何解决它。我需要将user.date_birthday转换为日期。所以我试了这个。
'use strict';
angular.module('TheNameApp')
.controller('SettingsCtrl', function ($scope, User, Auth) {
$scope.user = User.get();
$scope.errors = {};
console.log($scope.user); // display the resource
console.log($scope.user.date_birthday); //undefined
$scope.changeInformations = function(form) {
$scope.infos_submitted = true;
if(form.$valid) {
Auth.changeInformations({
gender: $scope.user.gender,
city: $scope.user.city,
country: $scope.user.country,
talent: $scope.user.talent,
date_birthday: $scope.user.date_birthday,
user_name: $scope.user.user_name,
email: $scope.user.email })
.then( function() {
$scope.infos_message = 'Done.'
})
.catch( function(err) {
err = err.data;
$scope.errors = {};
// Update validity of form fields that match the mongoose errors
angular.forEach(err.errors, function(error, field) {
form[field].$setValidity('mongoose', false);
$scope.errors[field] = error.message;
});
});
}
};
.html
<div class="form-group">
<label>Birthday</label>
<input type="date" name="date_birthday" class="form-control" ng-model="user.date_birthday"/>
</div>
user.date_birthday未定义,但我可以在 $scope.user 中看到它我的下一步需要这个
$scope.user.date_birthday = new Date($scope.user.date_birthday);
为什么我看不到我的属性?我该如何解决这个问题?
假设您的User
是资源,则.get()
是异步调用。使用回调:
User.get(function(user) {
user.date_birthday = new Date(user.date_birthday);
$scope.user = user;
});
相关文章:
- 同样,同样的错误'ahorcado.js:26未捕获类型错误:无法读取属性'beginPath'
- 当属性不一致时,如何根据属性对JS对象列表进行排序
- 无法获取属性'Id'使用Knockout.js的未定义或空引用API
- chart.js 2.0为数据集添加了新属性
- 无法读取属性'材料'未定义的Three.js
- 一个正则表达式,用于从JS中的HTML标记中删除id、样式和类属性
- 如何正确引用传递到淘汰中的当前元素的属性.JS
- 手动触发ember.js中的属性更改
- 无权访问我的控制器 Angular 中的属性.js 1.3
- 如何在培根中合并两个属性.js
- 如何从高图表动态更新 pointStart 系列属性.js
- 如何为补间分配额外的属性.js ( https://github.com/sole/tween.js/ )
- Ember 对象函数定义中的计算属性.js
- 动态插入文件时触发 onload 属性.js
- 创建新属性 - JS / 边缘动画
- 在 Backbone 中将函数设置为属性.js给了我一个错误,但如果我在初始化方法中设置它,它会起作用
- 在处理中不将“PImage”作为类属性.js
- 动态访问对象属性(JS)
- 迭代javascript对象并动态添加对象属性(JS对象中的键值对)
- IIS6无法获取类型属性;JS替换危险字符