一次。 也许我犯了一个愚蠢的错误,但我开始用Angular 4开始我的第一步,而且我的知识是新手。
我尝试build
生产版本以发布我的网站,但Angular CLI返回当前错误:
login.component.html中的错误:属性'密码'类型' LoginComponent'。
上不存在
login.component.html
<div class="container">
<div class="col-md-5 col-md-offset-1">
<form #loginForm="ngForm" class="loginForm">
<h3 class="text-center">Administrador</h3>
<hr>
<div class="alert alert-info" *ngIf="status.loading"> {{ status.loading }} </div>
<div class="alert alert-danger" *ngIf="status.error"> {{ status.error }} </div>
<div class="alert alert-success" *ngIf="status.success"> {{ status.success }} </div>
<div class="form-group">
<label for="tfEmail">Email</label>
<input type="text" class="form-control" name="email" ngModel id="tfEmail" #email="ngModel">
</div>
<div class="form-group">
<label for="tfPassword">Contraseña</label>
<input type="text" class="form-control" name="password" ngModel id="tfPassword" #email="ngModel">
</div>
<div class="text-center">
<button class="btn btn-primary btn-block" (click)="login(email, password)">Aceptar</button>
</div>
</form>
</div>
</div>
login.component.ts
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { AngularFireAuth } from 'angularfire2/auth';
import * as firebase from 'firebase/app';
import { ConfirmComponent } from '../../modal.component';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css', '../admin.component.css']
})
export class LoginComponent implements OnInit {
user: Observable<firebase.User>;
email: string;
password: string;
status = {
loading: '',
success: '',
error: ''
};
constructor(public afAuth: AngularFireAuth) {
this.user = afAuth.authState;
}
login(email, password) {
this.status.loading = 'Procesando datos...';
return new Promise((resolve, reject) => {
this.status = { loading: '', success: '', error: '' };
this.afAuth.auth.signInWithEmailAndPassword(email, password).then(_ => {
this.status.success = 'Login correcto. Redirigiendo...';
setTimeout(() => {
window.location.href = '/';
}, 3000);
}).catch(error => {
this.status.error = 'Ocurrió un error. Revise sus datos.';
console.error(error);
});
});
}
ngOnInit() {
}
}