为什么当括号跟随返回时,角度指令不起作用?
app.directive("alert", function () {
return {
restrict: "EA",
template: "<div>Alert!!</div>"
};
});
但是,当括号与回程相邻时,确实有效:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(new Scope(Scopes.DRIVE_APPFOLDER))
.requestIdToken("685357920901-sfghh9b8heq89b3g1l7gun3csuilur5c.apps.googleusercontent.com")
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, null)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
mAuth = FirebaseAuth.getInstance();
mAuthListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
} else {
Log.d(TAG, "onAuthStateChanged:signed_out");
}
}
};
}
@Override
public void onStart() {
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
}
@Override
public void onStop() {
super.onStop();
if (mAuthListener != null) {
mAuth.removeAuthStateListener(mAuthListener);
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
if (!task.isSuccessful()) {
Log.d("here", "not");
Log.w(TAG, "signInWithCredential", task.getException());
Toast.makeText(MainActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
else{
Log.d("here", "ohyeah");
Toast.makeText(MainActivity.this, "done", Toast.LENGTH_SHORT).show();
}
}
});
}
public void SignIn(View view) {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
Log.d("here", "o "+result);
Log.d("here", "o00000 "+result.isSuccess());
if (result.isSuccess()) {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = result.getSignInAccount();
firebaseAuthWithGoogle(account);
Log.d("here", "success");
} else {
Log.d("here", "fail");
}
}
}
答案 0 :(得分:3)
因为当你刚刚返回被认为不返回undefined
时(没有)。您必须在同一行返回一些内容,否则与return;
&安培;当你在同一行上有它时,它认为你从指令返回了对象(DDO
)。
答案 1 :(得分:1)
这是因为JavaScript会将return
作为单个操作,因为return
本身就是一个有效的操作。
第一个例子与
相同app.directive("alert", function () {
return;
{
restrict: "EA",
template: "<div>Alert!!</div>"
};
});
答案 2 :(得分:1)
这是javascript中自动逗号插入的经典案例。
当您将支架移动到下一个支架时,编译器会在您的线末端预先插入一个半冒号,认为您已经忘记了它。
app.directive("alert", function () {
return ;
{
restrict: "EA",
template: "<div>Alert!!</div>"
};
});