我有一个组件数组,我想显示该数组中的现有组件,但它不起作用,我怀疑在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) 我无法理解为什么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) 是将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) 在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) 我正在尝试使用 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) 客户端是否可以知道应用程序之前启动时是否发生过 ANR?
例如,用户使用某个应用程序10天,第10天发生ANR并关闭该应用程序,第11天用户再次打开该应用程序,此时是否可以知道该应用程序发生了ANR当前设备在其生命周期的任何时间点都会出现问题吗?