小编Jus*_*s10的帖子

通过 ComponentFactoryResolver 创建组件时更改检测不起作用

我有一个组件,使用 ComponentFactoryResolver 创建另一个组件。似乎工作正常,我可以通过@Input 访问数据。问题是 ngOnChanges 在组件启动或数据更改时永远不会被调用。但是,如果我使用 HTML 中的选择器以正常方式创建组件,它确实会触发。但这不是动态的,所以我只剩下 ComponentFactoryResolver。这是正常行为吗?

我的父组件有它的输入:

@ViewChild( MyDirective ) myHost: MyDirective;

然后它创建子组件,其输入是这样的:

@Input('key') key: String;
@Input('index') index: number;
Run Code Online (Sandbox Code Playgroud)

我正在创建这样的组件:

let item = new Item(ItemDropdownComponent, this.key, 0);
let componentFactory = this._componentFactoryResolver.resolveComponentFactory(item.component);
let viewContainerRef = this.myHost.viewContainerRef;
viewContainerRef.clear();
let componentRef = viewContainerRef.createComponent(componentFactory);
(<ItemInterfaceComponent>componentRef.instance).key = item.key;
(<ItemInterfaceComponent>componentRef.instance).index = item.index;
Run Code Online (Sandbox Code Playgroud)

components input angular2-directives angular

6
推荐指数
1
解决办法
4264
查看次数

Firestore 使用哪种数据类型作为时间戳?

我相信任何已经知道的人都会认为这是一个显而易见的问题,但我已经花了很多时间搜索文档。

我认为你会做这样的事情,但这不起作用:

import * as firebase from 'firebase/app';

export interface ChatMessage {
  message: string;
  dateSent: firebase.firestore.serverTimestamp();
}
Run Code Online (Sandbox Code Playgroud)

另外,我在某些地方看到过这个,但它对我也不起作用......

firebase.firestore.FieldValue.serverTimestamp();
Run Code Online (Sandbox Code Playgroud)

我只是得到 Namespace 'firebase.firestore' has no exported member 'FieldValue'.

timestamp firebase angular google-cloud-firestore

6
推荐指数
1
解决办法
1902
查看次数

Flutter:在没有上下文的情况下从InheritedWidgets访问数据吗?

我看到我可以build()像这样在方法内部访问InheritedWidgets :final inheritedWidget = ChronoApp.of(context);但是如果我想在其他地方访问它(例如在initState()没有上下文的情况下)怎么办。我该怎么做?

dart flutter inherited-widget

6
推荐指数
2
解决办法
3503
查看次数

Flutter:如何将Canvas / CustomPainter保存到图像文件?

我正在尝试从用户那里收集签名并将其保存到图像中。我已经做得足够远,可以在屏幕上绘制了,但是现在我想单击一个按钮以保存到图像并存储在数据库中。

这是我到目前为止的内容:

import 'package:flutter/material.dart';

class SignaturePadPage extends StatefulWidget {
  SignaturePadPage({Key key}) : super(key: key);

  @override
  _SignaturePadPage createState() => new _SignaturePadPage();
}
class _SignaturePadPage extends State<SignaturePadPage> {

  List<Offset> _points = <Offset>[];

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: GestureDetector(
        onPanUpdate: (DragUpdateDetails details) {
          setState(() {
            RenderBox referenceBox = context.findRenderObject();
            Offset localPosition =
            referenceBox.globalToLocal(details.globalPosition);
            _points = new List.from(_points)..add(localPosition);
          });
        },
        onPanEnd: (DragEndDetails details) => _points.add(null),
        child: new CustomPaint(painter: new SignaturePainter(_points)),
      ),
    );
  }
}

class SignaturePainter extends CustomPainter { …
Run Code Online (Sandbox Code Playgroud)

canvas image save dart flutter

6
推荐指数
3
解决办法
5123
查看次数

在Observable上使用wait时,应该使用什么代替toPromise()?

此页面显示"toPromise has been deprecated! (RxJS 5.5+)"但最近我一直在AngularFire2中使用它(当我只想要一个结果时),如下所示:

const foo = await this.afs.doc(`docPath`).valueChanges().toPromise();
Run Code Online (Sandbox Code Playgroud)

我不应该这样做吗?如果没有,那有什么await选择呢?

更新:

在下面的答案之后,我对此进行了更改:

const foo = await this.afs.doc(`docPath`).valueChanges().toPromise();
Run Code Online (Sandbox Code Playgroud)

...对此:

const foo = await (new Promise(resolve => this.afs.doc(`docPath`).valueChanges().pipe(first()).subscribe(result => resolve(result))));
Run Code Online (Sandbox Code Playgroud)

有人可以向我解释这是一种改进吗?似乎向我倒退了一步。

javascript promise rxjs angularfire2 angular

6
推荐指数
1
解决办法
3256
查看次数

如何在打字稿中访问Angular scss变量?

我正在尝试从我的应用程序中的其他位置访问主题颜色。我可以使用color =“ primary”来访问主要元素,重音符号和对材质元素发出警告,但有时颜色不是一种选择,例如当我想以编程方式访问颜色时。有人知道如何在其他地方访问主题变量吗?我认为,更具体地说,我试图以打字稿或CSS样式使用scss变量,无论完成什么工作,但是当我尝试使用变量时,只会出错。

elevation material-design angular

5
推荐指数
0
解决办法
7477
查看次数

如何从 Angular 4 中的 *ngFor 循环中断?

如何从 Angular 4 中的 *ngFor 循环中断?

我只希望这个循环在执行一次后中断。

  <div *ngFor="let thing of things">
    <div *ngIf="thing == otherThing">
      <h4>Sub Title</h4>
      ***BREAK HERE***
    </div>
  </div>
Run Code Online (Sandbox Code Playgroud)

templates ngfor angular

5
推荐指数
1
解决办法
6779
查看次数

如何在Flutter中创建服务/提供程序?

Let's say I need a user service which has all my user variables and functions, and another item service with all item variables and functions, etc etc. I want all this data and functions available throughout the project, passing the user data where it's needed, for example.

I suspect it has something to do with inherited widgets, but how does that work? Like, I see how I could use one inherited widget at the root level, but am I supposed …

dart flutter inherited-widget

5
推荐指数
1
解决办法
4393
查看次数

Dart:你如何让未来等待流?

我想等一个bool是真的,然后从Future返回,但我似乎无法让我的Future等待Stream.

Future<bool> ready() {
  return new Future<bool>(() {
    StreamSubscription readySub;
    _readyStream.listen((aBool) {
      if (aBool) {
        return true;
      }
    });
  });
}
Run Code Online (Sandbox Code Playgroud)

future stream dart

5
推荐指数
2
解决办法
2420
查看次数

如何使用 TypeScript 和 Node 正确导入 Firestore?

我正在构建一个 Angular 网络应用程序,我是这样导入的:

import * as firebase from 'firebase';
db = firebase.firestore();
Run Code Online (Sandbox Code Playgroud)

但最近我不断收到这个错误:

It looks like you're using the development build of the Firebase JS SDK.
When deploying Firebase apps to production, it is advisable to only import the 
individual SDK components you intend to use.

For the module builds, these are available in the following manner
(replace <PACKAGE> with the name of a component - i.e. auth, database, etc):

Typescript:
import * as firebase from 'firebase/app';
import 'firebase/<PACKAGE>';
Run Code Online (Sandbox Code Playgroud)

所以,很自然地,我把它改成了这样: …

import firebase typescript angular google-cloud-firestore

5
推荐指数
1
解决办法
1641
查看次数