我有一个对象,我试图在firebase中设置但不能这样做。 Bellow代码运行时没有错误,但firebase forge中没有 coursesinterestedin 字段。
控制器代码 -
$scope.filterA = {
coursesInterestedIn: [{ "eng": "What's", "ukr": "Що є" }, { "eng": "your", "ukr": "твоє" }, { "eng": "surname?", "ukr": "прізвище?" }]
};
$scope.register = function () {
Auth.register($scope.user).then(function(user) {
var abc = angular.fromJson(angular.toJson($scope.filterA));
console.log("This is it: -----> "+abc);
return Auth.login($scope.user).then(function() {
user.studentname = $scope.user.studentname;
user.studentphoto = $scope.user.studentphoto;
user.studentmobile = $scope.user.studentmobile;
user.email = $scope.user.email;
user.fathername = $scope.user.fathername;
user.occupation = $scope.user.occupation;
user.fathernumber = $scope.user.fathernumber;
user.coursesinterestedin = abc;
user.studentclass = $scope.user.studentclass;
user.studentstream = $scope.user.studentstream;
user.studentschool = $scope.user.studentschool;
/*user.studentcourse = $scope.user.studentcourse;*/
user.studentacademic = $scope.user.studentacademic;
user.studentabout = $scope.user.studentabout;
user.username = $scope.user.username;
user.password = $scope.user.password;
return Auth.createProfile(user);
}).then(function() {
$location.path('/');
});
}, function(error) {
$scope.error = error.toString();
});
};
服务代码 -
var ref = new Firebase(FIREBASE_URL);
...
createProfile: function (user) {
var profile = {
studentname: user.studentname,
studentphoto: user.studentphoto,
studentmobile: user.studentmobile,
email: user.email,
fathername: user.fathername,
occupation: user.occupation,
fathernumber: user.fathernumber,
coursesinterestedin: user.coursesinterestedin,
studentclass: user.studentclass,
studentstream: user.studentstream,
studentschool: user.studentschool,
/*studentcourse: user.studentcourse,*/
studentacademic: user.studentacademic,
studentabout: user.studentabout,
username: user.username,
password: user.password,
md5_hash: user.md5_hash
};
var yoref = new Firebase(FIREBASE_URL + 'profileForStudents');
var yoprofileRef = $firebase(yoref).$asObject();
return yoprofileRef.$set(user.uid, profile);
},
我在控制台中收到以下错误:
logged out
collegeauth.js:63 logged out
2auth.js:69 Happened and copied
auth.js:72 This is the complete object [object Object]
auth.js:73 Object {coursesInterestedIn: Array[0]}
auth.js:62 logged out
collegeauth.js:63 logged out
auth.js:93 This is it: -----> [object Object]
auth.js:37 @logins service College name is: kjb
auth.js:38 @logins service College email is: a@a.com
auth.js:55 logged in
auth.js:58 Object {provider: "password", uid: "simplelogin:171", id: "171", md5_hash: "d10ca8d11301c2f4993ac2279ce4b930", email: "a@a.com"…}
collegeauth.js:56 logged in
collegeauth.js:59 Object {provider: "password", uid: "simplelogin:171", id: "171", md5_hash: "d10ca8d11301c2f4993ac2279ce4b930", email: "a@a.com"…}
angular.js:9778 TypeError: undefined is not a function
at Object.Auth.createProfile (http://localhost:9000/scripts/services/auth.js:31:27)
at http://localhost:9000/scripts/controllers/auth.js:111:21
at wrappedCallback (http://localhost:9000/bower_components/angular/angular.js:11319:81)
at http://localhost:9000/bower_components/angular/angular.js:11405:26
at Scope.$eval (http://localhost:9000/bower_components/angular/angular.js:12412:28)
at Scope.$digest (http://localhost:9000/bower_components/angular/angular.js:12224:31)
at Scope.$apply (http://localhost:9000/bower_components/angular/angular.js:12516:24)
at http://localhost:9000/bower_components/angular/angular.js:14023:36
at completeOutstandingRequest (http://localhost:9000/bower_components/angular/angular.js:4300:10)
at http://localhost:9000/bower_components/angular/angular.js:4601:7
auth.js:55 logged in
auth.js:58 Object {provider: "password", uid: "simplelogin:171", id: "171", md5_hash: "d10ca8d11301c2f4993ac2279ce4b930", email: "a@a.com"…}
collegeauth.js:56 logged in
collegeauth.js:59 Object {provider: "password", uid: "simplelogin:171", id: "171", md5_hash: "d10ca8d11301c2f4993ac2279ce4b930", email: "a@a.com"…}