用户-list.page.html
<p-dataTable [value]="userser" [rows]="10" scrollable="true" scrollHeight="200px">
<p-column field="USER_NAME" header="USER ID"></p-column>
<p-column field="USER_ID" header="USER NAME" [sortable]="true"></p-column>
<p-column field="DEPT_NAME" header="DEPARTMENT" [sortable]="true"></p-column>
<p-column field="ACTIVE" header="ACTIVE" [sortable]="true"></p-column></p-dataTable>
用户-list.page.ts
import User from './services/user';
import {UserService} from './services/user.service';
export class Userdetails {
userser: User[];
constructor(private userservice: UserService) {}
ngOnInit() {
this.userservice.getUsers().subscribe((userser: any) => this.userser = userser);
}
}
用户-list.json
{"userdata":
{"userlist":[
{"USER_ID":"SS","USER_NAME":"KUMAR"},
{"USER_ID":"SUDHEER","USER_NAME":"SS"},
{"USER_ID":"BHARGAV","USER_NAME":"TEJ"}
]}
},
user-service.ts (用于绑定JSON文件中的值的HTTP服务)
@Injectable()
export class UserService {
constructor(private http: Http) {
}
getUsers(): Observable<User[]> {
return this.http.get('app/assets/user-list.json')
.map(response => response.json().data as User[]);
}
}