Guest User

Home component

a guest
Apr 11th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// <reference path="../../../node_modules/nativescript-pulltorefresh/pulltorefresh.d.ts" />
  2.  
  3. "use strict";
  4.  
  5. import {Component} from "angular2/core";
  6. import {Router} from "angular2/router";
  7. import {UserService} from "../../shared/user/user.service";
  8. import {Config} from "../../shared/config";
  9. import {NotificationsService} from "../../shared/notification/notifications.service";
  10. import {Notification} from "../../shared/notification/notification";
  11. import { registerElement, ViewClass } from "nativescript-angular/element-registry";
  12. import {PullToRefresh} from "nativescript-pulltorefresh";
  13.  
  14. registerElement("PullToRefresh", () => require("nativescript-pulltorefresh").PullToRefresh);
  15.  
  16.  
  17. @Component({
  18.     selector: 'home',
  19.     templateUrl: 'pages/home/home.html',
  20.     providers: [UserService, NotificationsService]
  21.  
  22. })
  23.  
  24.  
  25. export class HomePage {
  26.  
  27.     notificationsList: Array<Notification> = [];
  28.     public RefreshedTimes = 0;
  29.     public Message = "Pull to refresh";
  30.  
  31.     constructor(
  32.         private _userService: UserService,
  33.         private _router: Router,
  34.         private _notificationService: NotificationsService) {
  35.         this.loadNotifications();
  36.        
  37.  
  38.        
  39.     }
  40.  
  41.     public loadNotifications(){
  42.         this._notificationService.load()
  43.             .subscribe(res => {
  44.                 res.forEach((resObject) => {
  45.                     this.notificationsList.unshift(resObject);
  46.                 });
  47.             });
  48.     }
  49.  
  50.     public refreshPage(args: any) {
  51.         console.log("page refresh -> go");
  52.         setTimeout(() => {
  53.             args.object.refreshing = false;
  54.             this.loadNotifications();
  55.         }, 1000);
  56.     }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment