多个Angularfire拉请求失败

时间:2016-04-05 20:18:04

标签: angularfire

所以我需要能够一个接一个地拉出多个项目,无论出于何种原因,第二个" .on"从不执行。我有一个永远不会打印的console.log。

代码如下

#include<iostream>
#include<cstring>
#include<fstream>
using namespace std;
class student{
public:
virtual void read()=0;
virtual void display()=0;
virtual void write_student()=0;
virtual void c_eligibility(){}
virtual void show_student()=0;
};



class student_record:public student{
private:
int id;
string name;
string department;
string semester_name;
string grade;
float cgpa;
float gpa=0;
string subjects;
int f;
public:
void read(){}
void display(){}
void show_student(){}
void c_eligibility(){}
void write_student(){

cout<<"Enter students Name:";
cin>>name;
cout<<"Enter Students ID:";
cin>>id;
cout<<"Enter Students department:";
cin>>department;
cout<<"Please enter your semester name:";
cin>>semester_name;
cout<<"Please enter how many subjects you have taken:";
cin>>f;
cout<<"Please enter the subjects name and their Grade:"<<endl;
for(int i=1;i<=f;i++){
cout<<"Subject name:";
cin>>subjects;
cout<<"Grade=";
cin>>grade;


    if(grade=="A"){
        gpa=gpa+4.00;
    }
    else if(grade=="A-"){
        gpa=gpa+3.70;
    }
    else if(grade=="B+"){
        gpa=gpa+3.30;
    }
    else if(grade=="B"){
        gpa=gpa+3.00;
    }
    else if(grade=="B-"){
        gpa=gpa+2.70;
    }
    else if(grade=="C+"){
        gpa=2.30;
    }
    else if(grade=="C"){
        gpa=gpa+2.00;
    }
    else if(grade=="C-"){
        gpa=gpa+1.70;
    }
    else if(grade=="D+"){
        gpa=gpa+1.30;
    }
    else if(grade=="D"){
        gpa=gpa+1.00;
    }
    else if(grade=="F"){
        gpa=gpa+0.00;
    }


    cgpa=gpa/f;

    }


    cout<<"CGPA is:"<<cgpa<<endl;

    ofstream out ("c:\\windows\\temp\\Student.txt",ios::app);

    out << "Name = "       <<name          << endl;
    out << "Id = "         <<id            << endl;
    out << "Semester = "   <<semester_name << endl;
    out << "CGPA = "       <<cgpa          << endl;
    out.close();
   }


   };
class student_show:public student{
private:
int id;
string name;
string department;
string semester_name;
string grade;
float cgpa;

public:
void read(){}
void display(){}
void write_student(){}
void c_eligibility(){}
void show_student(){
ifstream out;
out.open("c:\\windows\\temp\\Student.txt",ios::app);
out        >>name;
out        >>id;
out        >>semester_name;
out        >>cgpa;

    cout << "Name = "       <<name          << endl;
    cout << "Id = "         <<id            << endl;
    cout << "Semester = "   <<semester_name << endl;
    cout << "CGPA = "       <<cgpa          << endl;

}




};

class eligibility:public student{
private:
float PHY,CHE,MAT;
int n,w,q;
public:

void read(){}
void display(){}
void show_student(){}
void write_student(){}
void c_eligibility(){
cout<<"Please enter your mark of PHY, CHE, MAT:"<<endl;
cin>>PHY;
cin>>CHE;
cin>>MAT;
if(PHY>=80 && CHE>=80 && MAT>=80){
    cout<<"Congratulation you are eligible for the CCNA course. If you   want to register now please enter 1 or 2 to main menu"<<endl;
    cin>>q;
    if(q==1){
        cout<<"There are only " <<ticketLeft3() <<" seats available press 1 to confirm the advanced booking"<<endl;
        cin>>w;
        if(w==1){
            ticketCounter3(w);

            cout<<"Thank you for the confirmation";
        }

    }

}
else
    cout<<"Please retake the subjects to have the required marks.";



}
int ticketCounter3( int x ){
int a;
a=ticketLeft3()-x;
ofstream in ("c:\\windows\\temp\\booking.txt");
in <<a;



}
int ticketLeft3()
{
int k;
ifstream out;
out.open("c:\\windows\\temp\\booking.txt");
out        >>k;
return k;


}



};


int main()
{

student* s;

int n;
char ch;


        while(n!=4)
    {
    cout<<"\tWelcome to Student Record System"<<endl<<endl;
    cout<<"\t==================================================";
    cout<<"\n\n\t1.Create Student Record";
    cout<<"\n\n\t2.Display Student Record";
    cout<<"\n\n\t3.CCNA Course Eligibility";
    cout<<"\n\n\t==================================================";
    cout<<"\n\n\tPlease Enter Your Choice (1-3) or 4 to exit: ";
    cin>>n;
    if(n==1){
            s = new student_record;
            s->write_student();
    }
    else if(n==2){
        s = new student_show;
        s-> show_student();
    }
    else if(n==3){
        s=new eligibility;
        s->c_eligibility();
    }


    }
    return 0;

}

为什么第二个.once会失败?永远不会打印输入。

1 个答案:

答案 0 :(得分:0)

找到了解决方法。使用

$scope.returnedObj = $firebaseObject(ref);
    $scope.returnedObj.$loaded().then(function () {...})