我正在尝试使用TypeScript在NodeJS中执行base64编码.
以下代码在JavaScript中正常工作.
当我在TypeScript中编写相同的东西并进行编译时,我得到Buffer is not find错误.
var base64Policy = new Buffer(stringPolicy, 'utf-8').toString('base64');
Run Code Online (Sandbox Code Playgroud)
有人可以帮我在TypeScript中做同样的事情.
我正在尝试使用Http服务进行ajax调用,这工作正常.
现在我想处理失败案件.例如,如果我们得到404或任何其他错误.
我使用以下代码.
import {Component,Inject} from '@angular/core';
import {Http, Response,HTTP_PROVIDERS} from '@angular/http';
import {DoService} from './service';
import 'rxjs/Rx';
import 'rxjs/add/operator/catch';
@Component({
selector: 'comp-one',
template: `<h2>My First Angular 2 App</h2>{{data}}
<input type="button" (click)="doSomething()" value="Do Http"/>`
})
export class ComponentOne {
constructor(public _http:Http){
console.log("It is from ComponentOne constructor..");
this._http = _http;
}
data:Object;
doSomething(){
console.log("It is from doSomething ComponentOne");
let temp:any = this._http.get('people.json')//people.json is not exist, intendedly maing any error
.map(res => res.json())
.catch((err:any)=>{ console.log("Something is wrong..")});// If i keep this line …Run Code Online (Sandbox Code Playgroud) 我在Angular2中寻找AngularJS ISolated(= operation)范围的类似功能.
我想更改子组件中的父组件值,以便我不需要使用任何EventEmitters.
以下是我的代码片段.
<component-1>
<div *ngFor="let row of listArray" >
<component-2 [inputData]="row.inputData" (outputEvent)= "onComponentChange($event)"> </component-2>
</div>
<component-2 [inputData]="inputData2" (outputEvent)= "onComponentChange($event)"> </component-2>
<component-2 [inputData]="inputData3" (outputEvent)= "onComponentChange($event)"> </component-2>
<component-2 [inputData]="inputData4" (outputEvent)= "onComponentChange($event)"> </component-2>
Run Code Online (Sandbox Code Playgroud)
@Component
component-1{
onComponentChange(newValue){
//where to keep the new value
//this.inputData2/inputData3/inputData4/listArray[i].inputData ???????????
}
}
@Component
component-2{
@Input() inputData:string;
@Output() outputEvent:EventEmitter<string>;
changeComponentValue(newValue){
this.outputEvent(newValue);
}
}
Run Code Online (Sandbox Code Playgroud)
我将更改组件-2中的[inputData]值,该值应反映在组件-1中.
在现有的@Output eventEmitter中,我无法找到哪个元素值已更改.