2016-11-04 163 views
0

我正在研究角度2並且我遇到了問題。角度2:如何創建對象,將角度翻譯爲角度2

我不知道怎麼在我的登錄功能創建對象(Angular1)

public logIn() { 
     let phone = this.user.number.replace(/\s+/g, ''); 
     let email = 'u' + phone + '@lunch24.com'; 
     this.af.auth.login({email: email, password: this.user.password}) 
      .then((state) => { 
       console.log(state) 
       var usersRef = firebase.database().ref('v1/users'); 
       this.af.database.object(usersRef.child(state.uid)) 
        .subscribe((snapshot) => { 
         console.log(snapshot) 
         var user = snapshot; 
         if (user.roles.driver != true) { 
          if (user.roles.admin) { 
           var admin = 1; 
          } else { 
           var admin = 0; 
          } 
          if (user.roles.operator) { 
           var operator = 1; 
          } else { 
           var operator = 0; 
          } 
          if (user.roles.individual_customer) { 
           var individual_customer = 1; 
          } else { 
           var individual_customer = 0; 
          } 
+0

VAR MyObj中= {}; –

+0

@ Lajos Arpad所以在構造函數中加入 this.user = {}; 這樣的功能 this.user.admin = user.roles.admin; –

回答

0
this.user = { 
          admin: snapshot.roles.admin, 
          operator: snapshot.roles.operator