Skip to content

Commit 41be780

Browse files
author
高宇桥
committed
添加 services
1 parent 3f55a3c commit 41be780

14 files changed

Lines changed: 349 additions & 101 deletions

src/app/Components/Tab/tab.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div class="page__bd" style="height: 100%;">
44
<div class="weui-tab">
55
<div class="weui-tab__panel">
6-
6+
77
</div>
88
<div class="weui-tabbar" >
99
<a href="javascript:;"

src/app/Components/Tab/tab.component.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { Component ,Input,Output,EventEmitter } from '@angular/core';
1+
import { Component ,Input,Output,EventEmitter,OnInit,SimpleChange } from '@angular/core';
22

33
import { AppState } from '../../app.service';
44

5+
//tab 数据源 数据格式约定
6+
import { TABITEM } from './tab.interface';
57

68
@Component({
79
selector: 'tab',
@@ -13,24 +15,32 @@ import { AppState } from '../../app.service';
1315
left: 0;}`],
1416
templateUrl: './tab.component.html'
1517
})
16-
export class TabComponent {
17-
@Input() items:String[];
18-
@Output() tabTap:EventEmitter<any> = new EventEmitter();
18+
export class TabComponent implements OnInit {
19+
@Input() items : TABITEM[];
20+
@Input() content : String;
21+
@Output() tabTap : EventEmitter<any> = new EventEmitter();
1922

20-
selectedItem : Object;
23+
selectedItem : TABITEM;
2124

2225
constructor(public appState: AppState) {
2326

2427
}
2528

2629
ngOnInit() {
2730
this.selectedItem = this.items[0];
31+
console.log(this.selectedItem);
2832
}
29-
tabChange(item:Object,event:Object){
33+
ngOnChanges(changes: {[propertyName: string]: SimpleChange}) {
34+
//设置 tab 颜色
35+
let item = changes['items'];
36+
if(item && item.currentValue.length!=0){
37+
this.selectedItem = this.items[0];
38+
}
39+
}
40+
tabChange(item:TABITEM,event:Object){
3041
this.selectedItem = item;
3142

32-
console.log(this.tabTap);
33-
this.tabTap.emit(null);
43+
this.tabTap.emit(item.text);
3444
}
3545
setClass(item){
3646
return {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface TABITEM{
2+
src :String;
3+
activeSrc :String;
4+
text :String;
5+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Injectable } from '@angular/core';
2+
import { Http ,Response } from '@angular/http';
3+
import { TABITEM } from './tab.interface';
4+
import { Observable } from 'rxjs/Observable';
5+
6+
@Injectable()
7+
export class TabServices {
8+
private url = '/assets/data.json';
9+
10+
constructor(private http: Http) {}
11+
12+
getData(): Observable<TABITEM[]> {
13+
return this.http.get(this.url)
14+
.map(this.extractData)
15+
// .catch(this.handleError);
16+
}
17+
18+
private extractData(res: Response) {
19+
return res.json() || { };
20+
}
21+
private handleError(error: any){
22+
let errMsg = (error.message) ? error.message :
23+
error.status ? `${error.status} - ${error.statusText}` : 'Server error';
24+
console.error(errMsg); // log to console instead
25+
return Observable.throw(errMsg);
26+
}
27+
28+
}

src/app/View/+detail/detail.component.js

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/View/+detail/detail.component.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/View/+detail/index.js

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/View/+detail/index.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)