Angular 5
什么时候创建和销毁服务,它的生命周期挂钩(如果有的话)是什么,它的数据如何在组件之间共享?
编辑:澄清一下,这不是关于组件生命周期的问题.这个问题是关于服务的生命周期.如果服务没有生命周期,那么组件和服务之间的数据流如何管理?
插入哈希映射时,是否总是要检查是否存在与要插入的密钥对应的空值?
例如,如果我想跟踪字符出现在单词中的次数,使用hashmap,我是否总是这样做:
if(hashMap.containsKey(ch)){
hashMap.replace(ch, 1+hashMap.get(ch));
}
else{
hashMap.put(ch, 1);
}
Run Code Online (Sandbox Code Playgroud)
或者有一个功能可以为我处理这个?
我正在尝试使用VS Code调试Angular 2应用程序。要将从IE启动的浏览器更改为Chrome,我安装了Chrome调试器。
这是launch.json包含的内容:
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
Run Code Online (Sandbox Code Playgroud)
启动项目(使用ng serve --open)并尝试调试后,我得到:
Error processing "launch": Error: Can't find Chrome - install it or set the "runtimeExecutable" field in the launch config.
<p>at Object.errP (C:\Users\rahs\.vscode\extensions\msjsdiag.debugger-for-chrome-4.1.0\node_modules\vscode-chrome-debug-core\out\src\utils.js:207:13)
<p>at launch.then (C:\Users\rahs\.vscode\extensions\msjsdiag.debugger-for-chrome-4.1.0\out\src\chromeDebugAdapter.js:52:57)
at anonymous
Run Code Online (Sandbox Code Playgroud)
我在同一个主题上提到了这样的问题,但是我使用的是Windows,而Windows特定的答案对我不起作用。
角5
为什么只有构造函数签名中使用访问修饰符限定的变量才能在整个类中被识别?
例如。
constructor(private n: number) {
}
fn(){
this.n = 6; //Allowed
}
Run Code Online (Sandbox Code Playgroud)
但
constructor(n: number) {
}
fn(){
this.n = 6; //Not allowed
}
Run Code Online (Sandbox Code Playgroud) I am able to use MatToolTip along with a button element:
<button mat-mini-fab color="primary" (click)="fn()">
<span matTooltip="myMessage">
<i class="material-icons">delete</i>
</span>
</button>
Run Code Online (Sandbox Code Playgroud)
But on trying to use it with an icon which is within a div or span tag, it doesn't work:
<div matToolTip="myMessage">
<i style="line-height: 0px; font-size: 25px; cursor: pointer; " (click)="fn()" class="material-icons">delete</i>
</div>
Run Code Online (Sandbox Code Playgroud)
What am I doing wrong?
数据:一系列大小相等的列表,必须沿列进行平均才能返回一个平均列表
statistics.mean()使用或之一对 python 中的上述数据进行平均是否更快,sum()/len()或者将其转换为 numpy 数组然后使用是否更快np.average()?
或者没有显着差异?
这个问题提供了使用哪种方法的答案,但没有提及与替代方案的任何比较。
我如何告诉Java我不需要初始化a以获得有效的程序并且不给我错误?
int a;
boolean b = true;
while (true) {
if (b == false) {
System.out.print(a);
break;
} else {
b = false;
a = 5;
}
}
Run Code Online (Sandbox Code Playgroud)
如果我不能,那么为什么这就是编译器的设计方式?
是否容易设计这样的编译器,或者这是一种确保我重构代码的机制?
这是不一样的问题,这一个