Просто несколько вопросов здесь.
Во-первых, когда я использую обновление браузера, он перезагружается обратно к /
вместо маршрута, который загружается до обновления. Ниже мое определение маршрутов.
const appRoutes: Routes = [
{ path: '', component: LandingModule, canActivate: [AuthGuardService] },
{ path: 'login', component: LoginModule, canActivate: [AuthGuardService] },
{ path: 'register', component: RegisterModule, canActivate: [AuthGuardService] },
{ path: 'dashboard', component: DashboardModule, canActivate: [AuthGuardService] },
{
path: 'vendors',
component: VendorModule,
canActivate: [AuthGuardService],
children: [
{ path: 'new', component: NewVendorModule, canActivate: [AuthGuardService] }
]
}
]
Во-вторых, когда я пытаюсь запустить ng build
или просто обновить страницу, я получаю эти ошибки. Как мне решить эти проблемы?
ОШИБКА:
src/app/app.component.ts(33,14): error TS2339: Property 'companies' does not exist on type '{}'.
БЛОК С ИСПОЛЬЗОВАННЫМ КОДОМ
sysUser.companies.forEach(function(company){
if(company.default){
defaultComp = company;
}
})
ERROR
src/app/services/users/users.service.ts(23,21): error TS2339: Property 'id' does not exist on type 'void'.
БЛОК С ИСПОЛЬЗОВАННЫМ КОДОМ
createRootUser(uid: string, company: string, companyName: string) {
return new Promise((resolve, reject) => {
firebase.firestore().collection("users").doc(uid).set({
'companies' : [
{
id : company,
name : companyName
}
]
}).then(docRef => {
resolve(docRef.id);
}).catch(error => {
reject(error);
})
})
}
ОБНОВЛЕНИЕ ОБЩИЙ APP.COMPONENT.TS
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { AngularFireAuth } from 'angularfire2/auth';
import { AngularFirestore } from 'angularfire2/firestore';
import * as firebase from 'firebase/app';
import { UsersService } from './services/users/users.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
public firebaseUser : any;
public systemUser: any;
public activeCompany: any;
constructor(public userServ: UsersService, public afAuth: AngularFireAuth, public afStor: AngularFirestore, private router: Router) {
const settings = {timestampsInSnapshots: true};
firebase.firestore().settings(settings);
firebase.auth().onAuthStateChanged(user => {
if(user) {
this.firebaseUser = user;
this.userServ.fetchUser(user.uid).then(sysUser => {
this.systemUser = sysUser;
var defaultComp : any;
sysUser.companies.forEach(function(company){
if(company.default){
defaultComp = company;
}
})
this.activeCompany = defaultComp;
}).catch(error => {
console.log('ERROR:', error);
})
} else {
this.firebaseUser = null;
}
});
}
public sidebarClosed: boolean = true;
public sidebarSetOne = true;
public sidebarSetTwo = true;
public sidebarSetThree = true;
logOut(): void {
firebase.auth().signOut();
}
}