import { Component } from '@angular/core'; import { FileUpload ,HtmlPost} from './../../app.class'; @Component({ moduleId: module.id, selector: 'news-add', templateUrl: './add.component.html' }) export class NewsAddComponent { FileUpload:FileUpload=new FileUpload(); image:string; news={title:"",author:"",content:"",image:""}; openFile(evn){ this.news.image=evn.target.files[0]; this.FileUpload.read(this.news.image,base64=>this.image=base64); } addNews(){ let http=new HtmlPost("post","http://school.cool1024.com/manager/news/add",res=>{let json=JSON.parse(res); alert(json.message); },()=>{alert("请求失败")}); http.append('title',this.news.title); http.append('author',this.news.author); http.append('content',this.news.content); http.append('image',this.news.image); http.send(); } }