我将这两个设置在一个组件中。
string script = @"param([string]$inParam)
$Username = 'SERVER\domain_user'
$Password = 'password'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$Cred = New-Object System.Management.Automation.PSCredential -ArgumentList $Username,$pass
Invoke-Command -ComputerName SERVER_TEST -Authentication Default -ScriptBlock {&""D:\Programs\myapplication.cmd"" $inParam} -Credential $Cred";
当我运行下面的http.get时,如何触发卡$ .emit(this.cards);
cards$: EventEmitter<any> = new EventEmitter();
private cards: Array<Cards>;
答案 0 :(得分:4)
就像你说cards$.emit(this.cards);
一样。将此添加到您的订阅onNext()
回调:
http.get('http://myendpoint')
.map((res: Response) => res.json())
.subscribe(res => {
this.cards = res;
this.cards$.emit(this.cards);
};
您还应该在其他地方订阅它以使用此值,例如:
constructor() {
this.cards$.subscribe(c => console.log(c));
}
答案 1 :(得分:0)
添加完整的回调:
this.cards = [];
http.get('http://myendpoint')
.map((res: Response) => res.json())
.subscribe(
res => { this.cards = res },
error => { console.log(error) },
() => this.cards$.emit(this.cards));
如果您期望多个事件并希望在最后一个事件之后执行代码,则此方法有效。从Http
你只能得到一个事件,在这种情况下@Sasxa的方法可能更容易。