在 Windows 10 中使用 Powershell。要更改提示:
PS C:\Users\b.HQ\Desktop\tsdev\my_folder>
PS my_folder> tsc
Run Code Online (Sandbox Code Playgroud)
我在 Powershell 中使用了以下命令:
function prompt {'PS ' + $(Get-Location | Split-Path -Leaf) + ">"}
Run Code Online (Sandbox Code Playgroud)
但是,每次我重新启动 Powershell 时,我都必须重新输入。 有没有办法坚持这种变化?
PS我对Powershell的配置一无所知,我一直在寻找解决方案,但除了我使用的提示外,我没有看到保存它的方法。
通过<img>Contentful CMS 或 background-image CSS URL加载的图像不会显示在 Facebook 的应用程序内浏览器中,例如:
"//images.ctfassets.net/yadj1kx9rmg0/wtrHxeu3zEoEce2MokCSi/cf6f68efdcf625fdc060607df0f3baef/quwowooybuqbl6ntboz3.jpg"
...使用 Https 托管,并在所有其他现代浏览器中加载,但不能在应用程序浏览器中加载 FB
我认为这是一个混合内容问题,但不知道如何?
这是我在《为什么 TypeScript 编译器通过两次检查来编译其可选链和空合并运算符?》末尾顺便问的一个后续问题。 正如 TypeScript 传奇人物jcalz在评论中指出的那样,它确实值得提出自己的问题。
// Why does the JavaScript treat
x?.y
// as
x === null || x === void 0 ? void 0 : x.y
// instead of
x === null || x === void 0 ? x : x.y
// ?
Run Code Online (Sandbox Code Playgroud)
当x == null,后者会保存null,而前者总是返回undefined。
现代浏览器?.本身就支持,因此我们可以测试此行为。
const test = () => {
console.log('undefined?.x\t\t==>\t', undefined?.x);
console.log('null?.x\t\t\t==>\t', null?.x);
console.log('null?.x === null\t==>\t', null?.x === null);
};
try {
eval('null?.x'); …Run Code Online (Sandbox Code Playgroud)我在Angular中使用过rxjs,并且我熟悉流中的catchError运算符的使用pipe,尤其是对于HttpClient(XHR)调用
我的问题是catchError手术如何进行?如何在后台捕捉错误?
https://www.learnrxjs.io/operators/error_handling/catch.html
import { throwError, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
//emit error
const source = throwError('This is an error!');
//gracefully handle error, returning observable with error message
const example = source.pipe(catchError(val => of(`I caught: ${val}`)));
//output: 'I caught: This is an error'
const subscribe = example.subscribe(val => console.log(val));
Run Code Online (Sandbox Code Playgroud)
更新:
使用“已接受答案”中的详细信息,我在StackBlitz TypeScript项目中对以下内容进行了测试。查看try / catch和subscriber.error的好例子:
import { throwError, of, Observable } from 'rxjs';
import { catchError, map } from 'rxjs/operators'; …Run Code Online (Sandbox Code Playgroud) return在使用逻辑AND运算符的箭头函数中使用隐式语句是否有任何副作用(不良影响)&&?
这可能包括捆绑程序或优化程序删除代码的问题
例子:
// With return
const tap = fn => val => {
fn(val);
return val;
};
Run Code Online (Sandbox Code Playgroud)
// Without explicit return
const tap = fn => val => fn(val) && val;
Run Code Online (Sandbox Code Playgroud)
// In case fn(val) returns a falsy value
const tap = fn => val => (fn(val) || true) && val;
Run Code Online (Sandbox Code Playgroud)
// Comma sequence (added from accepted answer)
const tap = fn => val => (fn(val), val);
Run Code Online (Sandbox Code Playgroud) 在我的模板中,我click附加了事件侦听器:
<a class="link-component" href="{{displayURL}}" (click)="handleClick($event)">
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用 HostListener 或 Renderer2,如下所示:
this.clickListener = this.renderer.listen(this.htmlElement, 'click'........
this.clickListener();
Run Code Online (Sandbox Code Playgroud)
但是,就template绑定的事件处理程序而言,它们会在组件销毁时自动删除吗?
我正在比较两个字符串,我想在比较之前将一个字符串小写.我怎样才能做到这一点?这是我的代码:
this.products = response.responseData.sort(function(a,b){
if(a.product.productName < b.product.productName){
return -1;
}
if(a.product.productName > b.product.productName){
return 1;
}
return 0;
});
Run Code Online (Sandbox Code Playgroud) 我正在使用一个库,它使用一种非常常见的BehaviorSubject模式从服务类中公开数据。与实现和我自己看到/使用的唯一显着区别是添加了一个pipewithshareReplay(1)运算符。我不确定是否shareReplay需要。如果有的话,shareReplay在这种情况下有什么影响?
// "rxjs": "^6.3.0"
this.data = new BehaviorSubject({});
this.data$ = this.data.asObservable().pipe(
shareReplay(1)
)
Run Code Online (Sandbox Code Playgroud)
注意:我已经阅读了许多关于 shareReplay 的文章,并且我看到了有关 shareReplay 和 Subject 的不同组合的问题,但不是这个特定的