小编Dan*_* T.的帖子

Angular Firestore 查询中的 get() 和 valueChanges() 有什么区别?

正如标题所说,我想问一下在 Angular Firestore 中执行查询时 get() 和 valueChanges() 之间有什么区别(如果有的话)。

在读取/成本方面,两者之间是否也有任何优点/缺点?

javascript firebase typescript angular google-cloud-firestore

11
推荐指数
2
解决办法
9302
查看次数

在 Android 设备上使用 Angular Ionic 加速计事件频率在前 5 分钟减慢

我在用

window.addEventListener('devicemotion', event => this.watchDeviceMotion(event))

watchDeviceMotion(event: any) {

  let motionData = {
    x: event.acceleration.x,
    y: event.acceleration.y,
    z: event.acceleration.z,
  }
  let rotationData = {
    alpha: event.rotationRate.alpha,
    beta: event.rotationRate.beta,
    gamma: event.rotationRate.gamma
  }

  if (this.getSensorData) {
    // console.log(JSON.stringify(motionData))
    // console.log(JSON.stringify(rotationData))
    this.userData.motionData.push(motionData)
    this.userData.rotationData.push(rotationData)
  }
}
Run Code Online (Sandbox Code Playgroud)

使用带有 Angular 的 Ionic 访问 Android 设备上的加速度计数据。在应用程序内部时,事件以 60 Hz 的频率运行,但当应用程序切换到后台时,频率在前 5 分钟内下降约 9-10 Hz,并且在某个时刻仍处于后台时,它会以 60 Hz 的频率返回并且无限期地保持这样。

我也在使用后台插件

this.backgroundMode.enable();
this.backgroundMode.on('activate').subscribe(() => {
  this.backgroundMode.disableWebViewOptimizations();
});
Run Code Online (Sandbox Code Playgroud)

我尝试将 disableBatteryOptimizations() 添加到具有 config.xml 中相应条件的后台插件,但仍然没有运气。

我还尝试了 Device Motion 和 Gyroscope 的插件,但它们的行为相同。

我应该如何防止频率变慢?有没有其他人遇到过这个问题?

android ionic-framework devicemotion angular ionic4

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

如何将 Tensorflow 数据集与 OpenCV 预处理结合使用?

我正在创建一个用于文本识别的管道,我想使用 Tensorflow Dtatasets 通过 OpenCV 的一些预处理来加载数据

我正在关注本教程 https://www.tensorflow.org/guide/datasets#applying_centric_python_logic_with_tfpy_func 并且我有这个预处理函数:

def preprocess(path, imgSize=(1024, 64), dataAugmentation=False):

    img = cv2.imread(path, cv2.IMREAD_GRAYSCALE)

    kernel = np.ones((3, 3), np.uint8)
    th, img = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY_INV + 
    cv2.THRESH_OTSU)
    img = cv2.dilate(img, kernel, iterations=1)

    # create target image and copy sample image into it
    (wt, ht) = imgSize
    (h, w) = img.shape
    fx = w / wt
    fy = h / ht
    f = max(fx, fy)
    newSize = (max(min(wt, int(w / f)), 1),
               max(min(ht, int(h / f)), …
Run Code Online (Sandbox Code Playgroud)

python opencv tensorflow tensorflow-datasets

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

如何缓解 Angular 中的加载屏幕?

我在 Angular 的 index.html 中创建了一个加载屏幕,例如:

<app-root>
    <div class="app-loading">
      <svg class="logo" viewBox="0 0 100 100" >

      </svg>
    </div>
</app-root>
Run Code Online (Sandbox Code Playgroud)

并应用了一些风格。但是在页面加载后,svg 突然消失了。

<style type="text/css">
body, html {
  height: 100%;
}
.app-loading {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
}
.app-loading .logo {
  height: 100px;
  width: 100px;
  transform-origin: center center;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
}
</style>
Run Code Online (Sandbox Code Playgroud)

当它消失时,我如何进行和缓出过渡?

html css angular

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

为什么动态添加 Angular matTooltip 时不起作用?

我有一个 SVG 元素,我想在 Angular 中的某个时刻添加一个 matTooltip。我观察到,如果我尝试像这样添加 matTooltip:

generate() {
  var svgEle = document.getElementById("testSVG");
  var rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
  rect.setAttribute('id', "rect");
  rect.setAttribute('x', "73");
  rect.setAttribute('y', "95");
  rect.setAttribute('class', "st01");
  rect.setAttribute('width', "407");
  rect.setAttribute('height', "328");
  rect.setAttribute('matTooltip', "Info about the action");
  svgEle.append(rect)
}
Run Code Online (Sandbox Code Playgroud)

使用html测试代码:

<div style="width:400px">
    <svg version="1.1" id="testSVG" xmlns="http://www.w3.org/2000/svg" 
    xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
    viewBox="0 0 1000 1000" style="enable-background:new 0 0 1000 1000;" 
    xml:space="preserve">
    <style type="text/css">
          .st01{fill:#F99191;}
          .st11{fill:#92B1F7;}
    </style>
    <rect x="638.5" y="146" class="st11" width="236" height="219" 
    matTooltip="Info about the action"/>
    </svg> 
</div>
<button mat-stroked-button (click)="generate()">Generate</button>
Run Code Online (Sandbox Code Playgroud)

它不起作用。

这种情况下到底是什么问题呢?

svg tooltip angular-material angular

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

如何使用 Materialize CSS 将文本输入居中?

我正在尝试使用 Materialize CSS 将输入文本居中,但“center”和“center-align”类似乎没有效果。我不知道我在这里错过了什么

<div class="section">
<div class="row center-align">
    <div class="input-field col s3 center-align">
        <input id="email" type="email" class="validate">
        <label for="email">Email</label>
    </div> 
</div>      
<div class="row">
        <div class="input-field col s3 center-align">
            <input id="password" type="password" class="validate">
            <label for="password">Password</label>
        </div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)

css material-design

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

在tf.keras.layers.Embedding中,为什么重要的是知道字典的大小?

与标题相同,在tf.keras.layers.Embedding中,为什么重要的是要知道字典的大小作为输入维?

tensorflow word-embedding

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

如何获取 Firebase 实时数据库中添加的最后一项?

我正在使用 Firebase 的实时数据库来实时更新图表内的值。但是,我不知道如何仅检索添加到数据库的最后一个值。

我在limitToLast 和 'child_added' do not work Together #1773中找到了一些解释,但我没有设法让它工作。

到目前为止,我设法做到了这一点:

this.items = db.list('/items').valueChanges()
this.items.forEach(item => {
  this.data = item;
  this.add(this.data[this.data.length-1])
  console.log(this.data)
})

add(point: any) {
   this.chart.addPoint(point)
}
Run Code Online (Sandbox Code Playgroud)

但我知道这根本没有效率。

firebase typescript firebase-realtime-database angularfire2 angular

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