0
我正在使用angular-fullstack生成器。无法在Login.controller中传递_id参数
我在将_id参数传递给某个函数时遇到了问题。 我试图做到的,是我创建了一个用户,我想创建的模式引用另一个数据用户的ID后
因此这里是我的代码
'use strict';
class SignupVendorController {
//end-non-standard
constructor(Auth, $state, $http) {
this.Auth = Auth;
this.$state = $state;
this.$http = $http;
this.submitted = false;
}
//start-non-standard
register(form) {
this.submitted = true;
if (form.$valid) {
this.Auth.createUser({
firstName: this.user.firstName,
lastName: this.user.lastName,
email: this.user.email,
password: this.user.password,
role: 'vendor'
})
.then(Auth => {
this.vendor = Auth.getCurrentUser;
this.createVendor(this.vendor._id);
console.log('user is ' + this.vendor.firstName);
console.log('vendor created');
// Account created, redirect to home
this.$state.go('main');
})
.catch(err => {
err = err.data;
this.errors = {};
// Update validity of form fields that match the mongoose errors
angular.forEach(err.errors, (error, field) => {
form[field].$setValidity('mongoose', false);
this.errors[field] = error.message;
});
});
}
}
createVendor(id) {
var vendor = {
category: ['publishing'],
_owner: id
}
this.$http.post('/api/vendors', vendor);
}
}
angular.module('aApp')
.controller('SignupVendorController', SignupVendorController);
我已经尝试了几种语法修改,但这一切都得到了this.vendor未定义的变量。
这样,例如
var vendor = Auth.getCurrentUser;
console.log('the user is ' + vendor.firstName);
代码无法读取这两种_id或您的名字。 任何形式的帮助将不胜感激。 谢谢!