小编dvr*_*rer的帖子

angular 2 ngfor显示数组中的组件

我有一个组件数组,我想显示该数组中的现有组件,但它不起作用,我怀疑在ngfor中创建并显示一个新组件,而不是数组中的那个,因为我确实看到新组件被创建但是使用默认值而不是传递给它们的当前值,我做错了什么?

HTML:

<div #visualTextDiv class = "visual_text" [ngStyle]=setStyles()>

  <div *ngFor="let lineCounter of visualDivArray">
    <app-visual-text-div></app-visual-text-div>
  </div>

</div>
Run Code Online (Sandbox Code Playgroud)

打字稿:

if(this.visualDivArray.length < currentDivIndex+1){
  let newv = new VisualTextDivComponent()
  this.visualDivArray.push(newv);
  console.log("creating new " + this.visualDivArray.length);
}

this.visualDivArray[currentDivIndex].setData(textValue);
Run Code Online (Sandbox Code Playgroud)

javascript typescript angular

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

angular 2 ViewChild不起作用

我无法理解为什么ViewChild当相同的确切代码在textarea元素上工作时返回null ,但它不起作用div

模板:

<div #refId class = 'line_counter' >
    {{lineNumber}}
</div>
Run Code Online (Sandbox Code Playgroud)

零件:

import {Component, OnInit, Input, ElementRef, ViewChild} from '@angular/core';
import {Globals} from "../../../globals";

@Component({
  selector: 'app-line-counter',
  templateUrl: './line-counter.component.html',
  styleUrls: ['./line-counter.component.css']
})
export class LineCounterComponent implements OnInit {

  @ViewChild('#refId') textDiv:ElementRef;

  @Input() lineNumber : number = 0;

  constructor() {
  }

  ngOnInit() {
    if(Globals.refLineCounter == null) {
      Globals.refLineCounter = this;
      //console.log(Globals.refLineCounter.getHeight());
      console.log(this.getHeight());
    }
  }

  getHeight(){
    return this.textDiv.nativeElement.height;
  }
}
Run Code Online (Sandbox Code Playgroud)

typescript angular2-template angular

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

将char添加到字符串并删除char数组

是将a char从a 添加char*到a std::string,然后delete[]char数组会导致UB?

还是在delete[]?之后处理字符串安全吗?

int buffer_size = 4096;
char* buffer = new char[buffer_size];

//here there was removed code that assign values to the buffer[i]    

std::string data;

for (int i = 0; i < buffer_size ; i++)
{
    data.push_back(buffer[i]);
}

delete[] buffer;

//is the data string content secured at this point?
Run Code Online (Sandbox Code Playgroud)

c++

4
推荐指数
2
解决办法
125
查看次数

opengl es 2.0 android c ++ glGetTexImage替代

在Windows上进行测试时,代码按预期工作,但在android glGetTexImage上不存在api,还有另一种方法可以从OpenGL获取所有像素,而无需在创建纹理之前将其缓存?

这是代码:

void Texture::Bind(int unit)
{
    glActiveTexture(GL_TEXTURE0 + unit);
    glBindTexture(GL_TEXTURE_2D, mTextureID);
}

GLubyte* Texture::GetPixels()
{
    Bind();

    int data_size = mWidth * mHeight * 4;

    GLubyte* pixels = new GLubyte[mWidth * mHeight * 4];

    glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);

    return pixels;
}
Run Code Online (Sandbox Code Playgroud)

opengl-es opengl-es-2.0

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

android c++ 对eglGetCurrentContext 的未定义引用

我正在尝试使用 C++ 获取 Android 上当前的 OpenGL 上下文。

但我收到编译时错误,如何获取当前上下文?

错误:

undefined reference to eglGetCurrentContext()
Run Code Online (Sandbox Code Playgroud)

代码:

#include <GLES2/gl2.h>
#include <EGL/egl.h>

void foo()
{
    EGLContext ctx = eglGetCurrentContext();
}
Run Code Online (Sandbox Code Playgroud)

c++ android opengl-es android-ndk opengl-es-2.0

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

ANR发生后是否有可能检测到?

客户端是否可以知道应用程序之前启动时是否发生过 ANR?

例如,用户使用某个应用程序10天,第10天发生ANR并关闭该应用程序,第11天用户再次打开该应用程序,此时是否可以知道该应用程序发生了ANR当前设备在其生命周期的任何时间点都会出现问题吗?

android

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