Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- new MyClass(someArg);
- import {Component, OnInit} from '@angular/core';
- export class App implements OnInit{
- constructor(){
- //called first time before the ngOnInit()
- }
- ngOnInit(){
- //called after the constructor and called after the first ngOnChanges()
- }
- }
- export class Users implements OnInit{
- user_list: Array<any>;
- constructor(private _userService: UserService){
- };
- ngOnInit(){
- this.getUsers();
- };
- getUsers(){
- this._userService.getUsersFromService().subscribe(users => this.user_list = users);
- };
- }
- export class Users implements OnInit{
- user_list: Array<any>;
- constructor(private _userService: UserService){
- };
- ngOnInit(){
- this.getUsers();
- };
- getUsers(){
- this._userService.getUsersFromService().subscribe(users => this.user_list = users);
- this.user_list.toUpperCase();
- };
- }
- import {Cmomponent, OnInit} from 'angular2/core';
- import {ExternalService} from '../externalService';
- export class app implements OnInit{
- constructor(myService:ExternalService)
- {
- this.myService=myService;
- }
- ngOnInit(){
- // this.myService.someMethod()
- }
- }
- export class User {
- email: string;
- password: string;
- lastLogin: Date;
- constructor(msg:string) {
- this.email = "";
- this.password = "";
- this.lastLogin = new Date();
- console.log("*** User class constructor " + msg + " ***");
- }
- Login() {
- }
- }
- import {Component} from "@angular/core";
- import {User} from "./../../shared/user/user"
- @Component({
- selector: "login-component",
- templateUrl: "pages/login/login.html",
- styleUrls: ["pages/login/login-common.css", "pages/login/login.css"]
- })
- export class LoginComponent {
- user: User = new User("property"); // ONE
- isLoggingIn:boolean;
- constructor() {
- this.user = new User("constructor"); // TWO
- console.log("*** Login Component Constructor ***");
- }
- ngOnInit() {
- this.user = new User("ngOnInit"); // THREE
- this.user.Login();
- this.isLoggingIn = true;
- console.log("*** Login Component ngOnInit ***");
- }
- submit() {
- alert("You’re using: " + this.user.email + " " + this.user.lastLogin);
- }
- toggleDisplay() {
- this.isLoggingIn = !this.isLoggingIn;
- }
- }
- JS: *** User class constructor property ***
- JS: *** User class constructor constructor ***
- JS: *** Login Component Constructor ***
- JS: *** User class constructor ngOnInit ***
- JS: *** Login Component ngOnInit ***
- export class TestClass{
- let varA: string = "hello";
- }
- constructor(private http: Http, private customService: CustomService) {}
- import { Component, OnInit } from '@angular/core';
- import { Router } from '@angular/router';
- @Component({
- selector: 'my-app',
- template: `<h1>App is running!</h1>
- <my-app-main [data]=data></<my-app-main>`,
- styles: ['h1 { font-weight: normal; }']
- })
- class ExampleComponent implements OnInit {
- constructor(private router: Router) {} //Dependency injection in the constructor
- // ngOnInit, get called after Component initialised!
- ngOnInit() {
- console.log('Component initialised!');
- }
- }
- import {Component} from '@angular/core';
- @Component({})
- class CONSTRUCTORTEST {
- //This is called by Javascript not the Angular.
- constructor(){
- console.log("view constructor initialised");
- }
- }
- new CONSTRUCTORTEST();
- import {Component} from '@angular/core';
- @Component({})
- class NGONINITTEST implements onInit{
- constructor(){}
- //ngOnInit calls by Angular
- ngOnInit(){
- console.log("Testing ngOnInit");
- }
- }
- let instance = new NGONINITTEST();
- instance.ngOnInit();
- <my-app>
- <child-comp [i]='prop'>
- MyAppView
- - MyApp component instance
- - my-app host element data
- ChildCompnentView
- - ChildComponent component instance
- - child-comp host element data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement