Advertisement
Guest User

Untitled

a guest
Aug 1st, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. new MyClass(someArg);
  2.  
  3. import {Component, OnInit} from '@angular/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 ***
  122.  
  123. export class TestClass{
  124. let varA: string = "hello";
  125. }
  126.  
  127. constructor(private http: Http, private customService: CustomService) {}
  128.  
  129. import { Component, OnInit } from '@angular/core';
  130. import { Router } from '@angular/router';
  131.  
  132.  
  133. @Component({
  134. selector: 'my-app',
  135. template: `<h1>App is running!</h1>
  136. <my-app-main [data]=data></<my-app-main>`,
  137. styles: ['h1 { font-weight: normal; }']
  138. })
  139. class ExampleComponent implements OnInit {
  140. constructor(private router: Router) {} //Dependency injection in the constructor
  141.  
  142. // ngOnInit, get called after Component initialised!
  143. ngOnInit() {
  144. console.log('Component initialised!');
  145. }
  146. }
  147.  
  148. import {Component} from '@angular/core';
  149. @Component({})
  150. class CONSTRUCTORTEST {
  151.  
  152. //This is called by Javascript not the Angular.
  153. constructor(){
  154. console.log("view constructor initialised");
  155. }
  156. }
  157.  
  158. new CONSTRUCTORTEST();
  159.  
  160. import {Component} from '@angular/core';
  161. @Component({})
  162. class NGONINITTEST implements onInit{
  163. constructor(){}
  164. //ngOnInit calls by Angular
  165. ngOnInit(){
  166. console.log("Testing ngOnInit");
  167. }
  168. }
  169.  
  170. let instance = new NGONINITTEST();
  171.  
  172. instance.ngOnInit();
  173.  
  174. <my-app>
  175. <child-comp [i]='prop'>
  176.  
  177. MyAppView
  178. - MyApp component instance
  179. - my-app host element data
  180. ChildCompnentView
  181. - ChildComponent component instance
  182. - child-comp host element data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement