import { Http, Headers } from '@angular/http';

@Component({

selector : "idea-manager",

template : requier('/IdeaManagerComponent.html')

})

export class IdeaManagerComponent {

public ideas : any[] = [];

API_URI = "/api/IdeaService";

constructor(private http:Http){

//출력

this.http.get(this.API_URI).subscribe(r=>{

this.ideas = r.json();

});

}

//입력

btnSave(formValue){

var headers = new Headers();

headers.append("Content-Type", "application/json");

this.http.post(

this.API_URI, JOSN.stringify(formValue), {headers:headers})

.subscribe(r => {

this.ideas.push(r.json());

});

}

}


-------------------------------------------------


<form role="form" #form="ngForm">

<div>

<label for="note">아이디어</label>

<div>

<input type="text" id="note" name="note"

[(ngModel)] = "note" />

</div>

</div>

<div>

<div>

<button (click)="btnSave(form.value)">저장</button>

</div>

</div>

</form>

'angular' 카테고리의 다른 글

visual studio code angular intellisense  (0) 2017.06.25
Json 바인딩  (0) 2017.03.01
ngModel 과 양방향 바인딩  (0) 2017.02.25
데이타 바인딩  (0) 2017.02.25
angular cli  (0) 2017.02.25

+ Recent posts