小编Har*_*ger的帖子

在模板中使用Observable

我试图在我的模板中使用一个observable:

<md-nav-list>
    <a md-list-item *ngIf="!isAuth() | async" [routerLink]="['login']" (click)="sidenav.toggle()">Login</a>
    <a md-list-item *ngIf="isAuth() | async" (click)="logout()" (click)="sidenav.toggle()">Logout</a>
</md-nav-list>
Run Code Online (Sandbox Code Playgroud)

在我的模块中:

  isAuth(): Observable<boolean> {
        return this.loginservice.getAuthenticated()
                   .map(user => { if(user){
                                    if(user.hasOwnProperty('uid')){
                                      return true;
                                    } else { 
                                      return false; 
                                    }
                                  } else {
                                    return false;
                                  }
                                })
      }
Run Code Online (Sandbox Code Playgroud)

所以我的问题:

如果我登录并且observable返回true - >很酷我的菜单项出现

但如果observable返回false - >我的菜单是空的 - >什么是错的?

typescript angularfire2 angular

8
推荐指数
1
解决办法
5281
查看次数

更新后 Firebase-Functions 错误。我能做什么?

我更新了我的 firebase 函数,现在我在 Firebase 控制台中收到此错误。代码仍然相同,但我现在收到一个错误:

/srv/node_modules/@google-cloud/firestore/build/src/collection-group.js:54
    async *getPartitions(desiredPartitionCount) {
          ^

SyntaxError: Unexpected token *
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:617:28)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/srv/node_modules/@google-cloud/firestore/build/src/index.js:39:28)
Run Code Online (Sandbox Code Playgroud)

这是我的云函数 TypeScript 源:

import * as functions from 'firebase-functions';
import admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

/********************************************************************/

exports.newChatMessage = functions.firestore
  .document('/games/{gameId}/chat/{chatId}')
  .onCreate((snap, context) => {

    const createData = snap.data();
    if(!createData) {
        return false;
    }

    const chatMessage = createData.message; …
Run Code Online (Sandbox Code Playgroud)

javascript node.js firebase google-cloud-functions

8
推荐指数
1
解决办法
2054
查看次数

将boolean从observable传递给observable

我想检查我的adminauthguard,如果用户设置了adminflag(在Firebase中使用angularfire2)

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):Observable<boolean> | boolean {
    return this.loginservice.af.auth.map((auth) =>  {
      if(auth == null) {
        return false;
      } else {
        this.membersservice.get(auth.uid).subscribe(users => {
          if(users.admin == true) {
            return true;
          } else {
            return false;
          }
        })
      }
    });
Run Code Online (Sandbox Code Playgroud)

如何在可观察的内部解析observable?

firebase typescript firebase-authentication angularfire2 angular

7
推荐指数
1
解决办法
1万
查看次数

当在离子路由器出口时,离子含量与离子头重叠

我正在使用最新版本的 ionic4(rc0) 并且我正在尝试<ion-header>在 root 的 app.component.ts 中创建我的。

<ion-app>
    <ion-header>
      <ion-toolbar color="primary">
        <ion-title>
          <img src="assets/atippr_logo.svg" class="atippr-header"/>
        </ion-title>

      </ion-toolbar>
    </ion-header>

    <ion-menu side="start">

      <ion-header>
        <ion-toolbar color="primary">
          <ion-title>Menu</ion-title>
        </ion-toolbar>
      </ion-header>

      <ion-content>
        <ion-list>
          <ion-item ion-item menuClose="start" href="/dashboard">
            <ion-icon name="apps" item-left></ion-icon>
            Dashboard
          </ion-item>
        </ion-list>
      </ion-content>

    </ion-menu>

    <ion-router-outlet main></ion-router-outlet>
</ion-app>
Run Code Online (Sandbox Code Playgroud)

后来我想<ion-content>在我的路由页面中设置我的。

<ion-content>
  Login
</ion-content>
Run Code Online (Sandbox Code Playgroud)

但是现在我的页面内容总是与 app.component.ts 的标题重叠,当我在 ionic3 中没有记错时,有一个标签添加 hasHeader="true" 但没有效果。

有人可以帮我吗?

ionic-framework angular ionic4

4
推荐指数
1
解决办法
1912
查看次数

如何使用sidenav的EventEmitter(onClose)

我想检查一下我的

<md-sidenav>
Run Code Online (Sandbox Code Playgroud)

正在关闭。有没有一种方法可以使用sidenav对象的EventEmitter onClose进行检查?你能给我一个例子吗?

angular-material2 angular

3
推荐指数
1
解决办法
5095
查看次数