2017-12-03 2 views
1

본문에 Firebase에서 가져온 값이 포함 된 링크가 포함 된 전자 메일을 보내려고합니다. 값을 성공적으로 검색하고 있지만 이미 나열된 링크에 추가하는 방법을 모르겠습니다. 내가 변수 hashKey 몸에 나열된 URL에 추가 할하지만 이것을 달성하는 방법을 잘 모르겠어요 원하는URL에 변수를 전달하려면 어떻게해야합니까?

sendinvite() { 
     var user = firebase.auth().currentUser; 
     var uid = user.uid; 

     firebase.database().ref('/userlist/' + uid + '/' + 'hashKey').once('value').then(function(snapshot) { 
     var hashKey = (snapshot.val()); 
     console.log(hashKey) 
     }); 

     var bcc = []; 
     for(var e in this.emailinputs){ 
     if (this.emailinputs[e].email==null || this.emailinputs[e].email=="" || !this.emailinputs[e].email.includes("@") || !this.emailinputs[e].email.includes(".")) 
     { 
      let alert = this.alerCtrl.create({ 
      title: 'Error!', 
      message: 'There was an error with an email address you entered.', 
      buttons: ['Ok'] 
      }); 
      alert.present() 
     }else { 
      bcc.push(this.emailinputs[e].email); 
     } 
     } 
     if(bcc.length > 0) { 
     let email = { 
      bcc: bcc, 
      subject: 'Nudget Invite', 
      body: '<a href="https://nudget-72ee4.firebaseapp.com/?hashkey='+hashKey+'">Join my grocery list!</a>', 
      isHtml: true 
     }; 
     this.emailComposer.open(email); 
     } 
} 

: 다음은 코드입니다. 1

편집 문자열에 변수를 추가 할 몸을 업데이트했습니다. 내가 참조 할 수 있도록 Firebase의 hashkey를 어디에 둘 수 있는지 잘 모르겠습니다.

+0

당신이 표준 쿼리 문자열을 사용하여 시도? 예 :'https : //nudget-72ee4.firebaseapp.com/? key = value' – Tigger

+0

@Tigger 나는 현재''Join my grocery list! ''을 가지고 있습니다. 문제는 내가 참조 할 hashKey 변수를 어디에 둘 수 있는지 모르겠다는 것입니다. – cfoster5

답변

0

내가보기에 가장 큰 문제는 'firekey ... function (snapshot) block'에 'hashkey'변수의 범위를 지정한다는 것입니다. 이것은 'uid'변수 근처의 맨 위에 정의되어야합니다. 그러면이 코드 모두가이를 참조 할 수 있습니다.

그런 다음 스냅 샷 기능에서 hashkey 앞에 'var'을 제거하면 기존 변수가 설정됩니다.

또한 이메일을 보내기 전에 'hashkey'에 비어 있지 않은 값이 있는지 확인해야합니다.

HTH, 짐

0

나는 문제가 여기에있다 생각 :

firebase.database().ref('/userlist/' + uid + '/' + 'hashKey').once('value').then(function(snapshot) { 
    var hashKey = (snapshot.val()); 
    console.log(hashKey) 
}); 

당신은 그 함수의 hashKey 외부에 액세스하려고 다음 익명 함수 내에서 var 이름 hashKey을 만들 수 있습니다.

는 시도 대신에 다음

var user = firebase.auth().currentUser; 
var uid = user.uid; 
var hashKey = null; 

firebase.database().ref('/userlist/' + uid + '/' + 'hashKey').once('value').then(function(snapshot) { 
    hashKey = (snapshot.val()); 
    console.log(hashKey) 
}); 

... snip ... 

    body: '<a href="https://nudget-72ee4.firebaseapp.com/?hashkey='+ ((hashKey == null) ? 'no-key' : hashKey) +'">Join my grocery list!</a>', 

... snip ... 
관련 문제