本文整理汇总了TypeScript中angularfire2.AngularFire.object方法的典型用法代码示例。如果您正苦于以下问题:TypeScript AngularFire.object方法的具体用法?TypeScript AngularFire.object怎么用?TypeScript AngularFire.object使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类angularfire2.AngularFire
的用法示例。
在下文中一共展示了AngularFire.object方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: Date
this.af.auth.login({ email: this.rs.genEmail(phone), password: this.password }).then((authData) => {
//console.log("Rs2:" + authData.uid);
this.authData = authData;
//localStorage.setItem('uid', authData.uid);
this.rs.uid = authData.uid;
var usersRef = this.af.object("/users/" + this.authData.uid);
usersRef.update({
lastlogin: (new Date()).toISOString()
});
usersRef.subscribe(res => {
let role = res.role;
this.rs.dealer = res.dealername;
this.rs.role = res.role;
this.rs.uid = res.uid;
this.rs.ownerId = res.ownerid;
this.rs.phone = res.phone;
this.rs.fname = res.fname;
this.rs.lname = res.lname;
//console.log("role:" + role + " getRole:" + this.rs.role);
}
);
}).catch((error) => {
示例2:
af.auth.asObservable().filter(user => user !== null).subscribe(user => { // Skip null values
this.boardURL = 'users/' + user.uid + '/boards/' + routeParams.get('key');
this.board = af.object(this.boardURL);
this.lists = af.list(this.boardURL + '/lists', { query: { orderByChild: 'priority' } });
this.tasks = af.list(this.boardURL + '/tasks', { query: { orderByChild: 'priority' } });
this.listObservable = af.list(this.boardURL + '/lists');
this.taskObservable = af.list(this.boardURL + '/tasks');
});
示例3: updateWorkout
updateWorkout(workout: Workout, callback = (workoutKey) => {}) {
let key = workout["$key"];
delete workout["$key"];
const promise = this.af.object("/workouts/" + key).update(workout);
promise.then(_ => {
callback(key);
}).catch(err => {
console.log(err);
callback(false);
});
}
示例4: updateExercise
updateExercise(exercise: Exercise, callback = (exerciseKey) => {}) {
let key = exercise["$key"];
delete exercise["$key"];
const promise = this.af.object("/exercises/" + key).update(exercise);
promise.then(_ => {
callback(key);
}).catch(err => {
console.log(err);
callback(false);
});
}
示例5: getAssignment
getAssignment(id: string, callback = (assignment) => {}) {
let sub = this.af.object("/assignments/" + id).subscribe((assignment) => {
sub.unsubscribe();
if (!assignment) {
callback(false);
return;
}
assignment.$key = id;
callback(assignment);
return;
});
}
示例6: getWorkout
getWorkout(id: string, callback = (workout) => {}) {
let sub = this.af.object("/workouts/" + id).subscribe((workout) => {
sub.unsubscribe();
if (!workout) {
callback(false);
return;
}
workout.$key = id;
callback(workout);
return;
});
}
示例7: getExercise
getExercise(id: string, callback = (exercise) => {
}) {
let sub = this.af.object("/exercises/" + id).subscribe((exercise) => {
sub.unsubscribe();
if (!exercise) {
callback(false);
return;
}
exercise.$key = id;
callback(exercise);
return;
});
}
示例8: if
dragulaService.drop.subscribe(([bag, element, target, source, next]) => {
// Look at the adjacent tasks in the list and pick a priority in the middle
let prev = element.previousElementSibling;
if (bag === 'taskBag') {
let observables: Observable<Task>[] = [Observable.of(undefined), Observable.of(undefined), Observable.of(undefined)];
// Get the keys from the DOM. Stored in data-key attributes.
if (prev != null && prev.className === 'task') observables[0] = (af.object(this.boardURL + '/tasks/' + prev.dataset.key));
if (element != null && element.className === 'task') observables[1] = (af.object(this.boardURL + '/tasks/' + element.dataset.key));
if (next != null && next.className === 'task') observables[2] = (af.object(this.boardURL + '/tasks/' + next.dataset.key));
Observable.zip(...observables) // Combine the observables then subscribe asynchronously
.take(1) // only subscribe once
.subscribe(([previousTask, movedTask, nextTask]: Task[]) => {
let lower = -4; // arbitrary
let upper = 4; // arbitrary
if (previousTask && previousTask.priority != null) {
lower = previousTask.priority;
} else if (nextTask && nextTask.priority != null) {
lower = nextTask.priority - 4;
}
if (nextTask && nextTask.priority != null) {
upper = nextTask.priority;
} else if (previousTask && previousTask.priority != null) {
upper = previousTask.priority + 4;
}
// Update the priority of the moved task in the database
movedTask.priority = lower + (Math.abs(upper - lower) / 2);
// Check if it swapped to a different list
if (target.dataset.key !== source.dataset.key) {
movedTask.list = target.dataset.key;
}
this.taskObservable.update(element.dataset.key, movedTask);
});
} else if (bag === 'listBag') {
// TODO reorder the lists, similar as above
}
});
示例9: updateAssignment
updateAssignment(assignment: Assignment, callback = (assignmentKey) => {}) {
let key = assignment["$key"];
let exercisekey = assignment.exercise['$key'];
delete assignment["$key"];
delete assignment.exercise;
// console.log(assignment);
const promise = this.af.object("/assignments/" + key).update(assignment);
promise.then(_ => {
console.log("GOT", key);
callback(key);
}).catch(err => {
console.log(err);
callback(false);
});
}
示例10: addTask
addTask(listKey, input) {
let push = priority => {
let task: Task = { list: listKey, text: input.value, priority };
this.taskObservable.push(task);
input.value = '';
};
let lastTask = document.querySelector(`ul[data-key="${listKey}"] li:last-child`);
if (!lastTask) {
push(0);
return;
}
this.af.object(this.boardURL + '/tasks/' + lastTask.attributes['data-key'].value)
// TODO lastTask.dataset.key (can we use this? or is it only available in some browsers?)
.subscribe((value: Task) => {
push(value.priority + 2);
});
}