Advertisement
Guest User

Untitled

a guest
Aug 11th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. new MyClass(someArg);
  2.  
  3. import {Component, OnInit} from 'angular2/core';
  4.  
  5. export class App implements OnInit{
  6. constructor(){
  7. //called first time before the ngOnInit()
  8. }
  9.  
  10. ngOnInit(){
  11. //called after the constructor and called after the first ngOnChanges()
  12. }
  13. }
  14.  
  15. export class Users implements OnInit{
  16.  
  17. user_list: Array<any>;
  18.  
  19. constructor(private _userService: UserService){
  20. };
  21.  
  22. ngOnInit(){
  23. this.getUsers();
  24. };
  25.  
  26. getUsers(){
  27. this._userService.getUsersFromService().subscribe(users => this.user_list = users);
  28. };
  29.  
  30.  
  31. }
  32.  
  33. export class Users implements OnInit{
  34.  
  35. user_list: Array<any>;
  36.  
  37. constructor(private _userService: UserService){
  38. };
  39.  
  40. ngOnInit(){
  41. this.getUsers();
  42. };
  43.  
  44. getUsers(){
  45. this._userService.getUsersFromService().subscribe(users => this.user_list = users);
  46. this.user_list.toUpperCase();
  47. };
  48.  
  49.  
  50. }
  51.  
  52. import {Cmomponent, OnInit} from 'angular2/core';
  53. import {ExternalService} from '../externalService';
  54.  
  55. export class app implements OnInit{
  56. constructor(myService:ExternalService)
  57. {
  58. this.myService=myService;
  59. }
  60.  
  61. ngOnInit(){
  62. // this.myService.someMethod()
  63. }
  64. }
  65.  
  66. export class User {
  67. email: string;
  68. password: string;
  69. lastLogin: Date;
  70.  
  71. constructor(msg:string) {
  72. this.email = "";
  73. this.password = "";
  74. this.lastLogin = new Date();
  75. console.log("*** User class constructor " + msg + " ***");
  76. }
  77.  
  78. Login() {
  79. }
  80. }
  81.  
  82. import {Component} from "@angular/core";
  83. import {User} from "./../../shared/user/user"
  84.  
  85. @Component({
  86. selector: "login-component",
  87. templateUrl: "pages/login/login.html",
  88. styleUrls: ["pages/login/login-common.css", "pages/login/login.css"]
  89. })
  90. export class LoginComponent {
  91.  
  92. user: User = new User("property"); // ONE
  93. isLoggingIn:boolean;
  94.  
  95. constructor() {
  96. this.user = new User("constructor"); // TWO
  97. console.log("*** Login Component Constructor ***");
  98. }
  99.  
  100. ngOnInit() {
  101. this.user = new User("ngOnInit"); // THREE
  102. this.user.Login();
  103. this.isLoggingIn = true;
  104. console.log("*** Login Component ngOnInit ***");
  105. }
  106.  
  107. submit() {
  108. alert("You’re using: " + this.user.email + " " + this.user.lastLogin);
  109. }
  110.  
  111. toggleDisplay() {
  112. this.isLoggingIn = !this.isLoggingIn;
  113. }
  114.  
  115. }
  116.  
  117. JS: *** User class constructor property ***
  118. JS: *** User class constructor constructor ***
  119. JS: *** Login Component Constructor ***
  120. JS: *** User class constructor ngOnInit ***
  121. JS: *** Login Component ngOnInit ***
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement