angular2组件开发,我把它放到index.html中使用@Input这个传值,在组件里没有获取到,怎么破这个组件的传值问题,还有就是想问下就是index这个首页里是不是放的都是整个页面的组件,而不是小组件拼成的页面
应该在app.html/component中进行组件开发。index.html中: <body> <app-root>Loading...</app-root> </body> app-root标签与app.component中的selector相对应: @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) 把app.html作为父组件,子组件都是在其基础上拼接而成。 根据评论再补充下网络请求的内容: import {Headers, Http, RequestOptions} from "@angular/http"; request={ 'id':20, 'name':'Tony' }; public requestPost(requestUrl, request) { const body: string = JSON.stringify(request);//这句是关键 const header: any = new Headers({'Content-Type': 'application/json'}); const options: any = new RequestOptions({headers: header}); return this.http.post(requestUrl, body, options);//http需要导入包 }
应该在app.html/component中进行组件开发。
index.html中:
app-root标签与app.component中的selector相对应:
把app.html作为父组件,子组件都是在其基础上拼接而成。
根据评论再补充下网络请求的内容: