我的主要 HTML
<div>
<block></block>
<block></block>
</div>
Run Code Online (Sandbox Code Playgroud)
我的组件
import {Component} from '@angular/core';
import {Observable} from 'rxjs/rx';
import {HTTP_PROVIDERS} from '@angular/http';
import {OnInit} from '@angular/core';
import {TestService} from './data.service'
@Component({
selector : 'block',
template : `
<div class="col-lg-4" style="color:blue">{{_list && _list[0].name}}</div>
`,
providers : [HTTP_PROVIDERS,TestService]
})
export class TestComponent implements OnInit{
_list : any[];
constructor(private _testDataService : TestService){}
ngOnInit(){
this._testDataService.getData()
.subscribe(list => this._list = list);
}
}
Run Code Online (Sandbox Code Playgroud)
我想在同一页面中重用组件来显示不同服务调用的不同数据
angular ×1