小编use*_*875的帖子

如何注入动态创建的组件的服务

export interface InfoPanelComponent {
    data: any;
}

export class ComplaintsComponent implements OnInit, InfoPanelComponent {
   data: any;             
   constructor(private navigationService: NavigationService, private activatedRoute: ActivatedRoute) {
   }

  onCancelClicked() {
      console.log(this.navigationService);
      this.navigationService.hidePanel(this.data.key, this.activatedRoute);
  }
}
Run Code Online (Sandbox Code Playgroud)

问题是,这this.navigationService是未定义的。服务本身在 中提供,app.modules.ts并且可以成功注入到其他组件中。

我想它不起作用的原因是上面的组件(以及将来的更多组件)是动态创建的:

private addPanel(item: InfoPanelItem, itemKey: string): void {
      const componentFactory = this.componentFactoryResolver.resolveComponentFactory(item.component);
      const viewContainerRef = this.infopanelHost.viewContainerRef;

      // create new component
      const componentRef = viewContainerRef.createComponent(componentFactory);

      (<InfoPanelComponent>componentRef.instance).data = item.data;   
  }
Run Code Online (Sandbox Code Playgroud)

我想因此没有注入服务。有没有办法一般地注入组件所需的所有依赖项?请注意,这ComplaintsComponent只是一个示例,还有更多示例可能需要不同的服务。

angular

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

6502 汇编程序 - RTS 命令和堆栈

我必须回答以下有关6502汇编语言的问题:

“在堆栈上,有以下值(顶部元素在前):0x01, 0x02, 0x03, 0x04, 0x05, 0x06 地址0xc000是指令jsr 0xABCD。在获取/执行周期后,哪个值将存储在程序计数器中,堆栈的顶部元素是什么?”

我知道程序计数器将为0xABCD,但我对堆栈元素感到困惑。我知道在 6502 架构中,栈是从上到下(从0x01FF0x0100)增长的。所以,我假设,堆栈指针指向 element 0x01,对吗?

现在,返回地址应该是program counter + 3,因为有next命令,所以我会说,0xc003将被压入堆栈,但以小端顺序,因此c0将是顶部元素。那是对的吗?

assembly 6502 subroutine

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

[]运算符在c ++中重载get和set操作

我有以下课程:

class mem
{
private:
    char _memory[0x10000][9];

public: 
    const (&char)[9] operator [] (int addr);    
}
Run Code Online (Sandbox Code Playgroud)

我的目标是能够mem像使用数组一样使用类,而后期的实现会更复杂.所以,我应该能够

  • 像'mem [0x1234]'一样访问它以返回对9个字符数组的引用
  • 写入'mem [0x1234] ="12345678\0";'

这是我试过的:

#include "mem.h"

const (&char)[9] mem::operator [] (int addr)
{
    return &_memory[addr];
}
Run Code Online (Sandbox Code Playgroud)

但是,它说方法"必须有一个返回值",我认为我已经定义了(&char)[9],但是作为这个定义,我得到错误消息"期望一个标识符".

c++ arrays reference operator-overloading

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

将角度服务传递给类和基类

我有以下课程:

export class CellLayer extends BaseLayer {

    constructor(name: string, type: LayerType, private mapService: MapService) {
        super(name, type, mapService);
    }
}
Run Code Online (Sandbox Code Playgroud)

和相应的抽象类:

export abstract class BaseLayer implements ILayer {

    private _name: string;
    private _type: LayerType;

    constructor(name: string, type: LayerType, private mapService: MapService) {
        this._name = name;
        this._type = type;
    }
}
Run Code Online (Sandbox Code Playgroud)

全局MapService对象应该传递给这两个类.

但是,我现在收到以下错误:

类型具有私有属性"mapService"的单独声明.(6,14):Class'CellLayer'错误地扩展了基类'BaseLayer'.

angular

3
推荐指数
2
解决办法
1153
查看次数

如何纠正功能范围?

在我的模板中,我使用了一些渲染步进器的第三方组件,您可以在这些组件之间进行导航:

<my-stepper step="{{ currentStep }}" steps-label="steps"
   [stepChangeCallback]="stepChangeCallback">
   <my-stepper-step>First</my-stepper-step>
   <my-stepper-step>First</my-stepper-step>
   <my-stepper-step>First</my-stepper-step>
</my-stepper>
Run Code Online (Sandbox Code Playgroud)

export class HeaderComponent implements OnInit {
   currentStep = 0;

   stepChangeCallback(selectedStep) { 
     this.currentStep = selectedStep; // PROBLEM: this does not point to HeaderComponent
   }
}
Run Code Online (Sandbox Code Playgroud)

所以我想我可以使用固定的this指针生成一个新函数:

getStepChangeCallbackFunction() {
   return this.stepChangeCallback.bind(this);
}
Run Code Online (Sandbox Code Playgroud)

[stepChangeCallback]="getStepChangeCallbackFunction()"

这确实有效,但是,我看到内存消耗不断增加,并且该网站最终会导致浏览器崩溃,因为它不断生成新的功能副本。

还有其他解决方案吗?

javascript angular

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

如何在C++中安全地存储AES加密密钥?

我在客户端 - 服务器应用程序中使用AES进行加密.

目前,我已经简单地定义了一个静态对称密钥,它在客户端和服务器中都是硬编码的.

我感觉这不是很安全,因为通过反转/反汇编可执行文件来获取密钥应该不会太难.

另一方面,我没有看到像Diffie-Hellman这样的密钥交换如何解决问题,因为密钥最终将在客户端的内存中结束,并且(可能)也可以通过某种方法提取.

我正在读到所有这些,包括加密和/或混淆密钥,都不安全.但它是如何安全地完成的?

c++ encryption

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

为什么LINQ排序我的数组?

我有以下代码:

int[] numbers = new int[] { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
int i = 0;
var query =
     from n in numbers
     select ++i;

foreach (var n in query)
    Console.WriteLine("number = {0}, counter = {1}", n, i);
Run Code Online (Sandbox Code Playgroud)

为什么即使我没有给出输出,输出也按递增顺序排序orderby

number = 1, counter = 1
number = 2, counter = 2
number = 3, counter = 3
number = 4, counter = 4
number = 5, counter = 5
number = 6, …
Run Code Online (Sandbox Code Playgroud)

c# linq

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