zoaseo
To Infinity And Beyond
zoaseo
전체 방문자
오늘
어제
  • 분류 전체보기 (763)
    • 개발이 좋아서 (381)
      • SAP가 좋아서 (3)
      • Java가 좋아서 (42)
      • Spring이 좋아서 (50)
      • JPA가 좋아서 (0)
      • QueryDSL이 좋아서 (26)
      • Docker가 좋아서 (7)
      • Redis가 좋아서 (7)
      • AWS가 좋아서 (5)
      • CI/CD가 좋아서 (6)
      • Troubleshooting이 좋아서 (4)
      • Kotlin이 좋아서 (7)
      • SQL이 좋아서 (6)
      • HTTP가 좋아서 (21)
      • JavaScript가 좋아서 (30)
      • TypeScript가 좋아서 (6)
      • Vue가 좋아서 (21)
      • Flutter가 좋아서 (61)
      • React가 좋아서 (20)
      • Redux(React)가 좋아서 (2)
      • Angular가 좋아서 (22)
      • HTML이 좋아서 (9)
      • CSS가 좋아서 (15)
      • PHP가 좋아서 (9)
      • Illustrator가 좋아서 (2)
    • 노력이 좋아서 (169)
    • 결과물이 좋아서 (14)
    • 코딩연습이 좋아서 (168)
      • 이론이 좋아서 (62)
      • SQL이 좋아서 (90)
    • 유용한 사이트가 좋아서 (28)
    • Github (2)

인기 글

티스토리

hELLO · Designed By 정상우.
zoaseo
개발이 좋아서/Angular가 좋아서

Angular - 튜토리얼03

Angular - 튜토리얼03
개발이 좋아서/Angular가 좋아서

Angular - 튜토리얼03

2022. 9. 26. 17:01

1) app.component.ts

import { Component } from '@angular/core';

const array : Array<string> = ['data0','data1','data2'];

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title : string = 'firstStudy';

  constructor() { 

  }
  public clickAfterPrint () : void{
    this._innerFunc();
    console.log(array);
    console.log(this.title);
  }
  private _innerFunc() {
    array.push('data' + array.length);
  }
}

 

* 클래스 안에 사용하는 함수 또는 클래스 변수는 this를 사용하지만, 클래스 외부에서 선언한 변수 및 함수는 this를 사용하지 않습니다.

2)

app.component.ts

import { Component } from '@angular/core';

const array : Array<string> = ['data0','data1','data2'];

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title : string = 'firstStudy';

  showArray : Array<string>;

  constructor() { // 생성자는 오직 1번만 클래스 파일이 생성될 때 동작합니다.
    this.showArray = array;
  }
  public clickAfterPrint () : void{
    this._innerFunc();
    console.log(array);
    console.log(this.title);
  }
  private _innerFunc() {
    array.push('data' + array.length);
  }
}

app.component.html

<button (click)="clickAfterPrint()">{{title}} <- 당신이 입력한 변수 title</button>
<div *ngFor="let item of showArray">{{item}}</div>

'개발이 좋아서 > Angular가 좋아서' 카테고리의 다른 글

Angular - 튜토리얼05_컴포넌트, 모듈(로그인)  (0) 2022.09.28
Angular - 튜토리얼04_컴포넌트, 모듈  (0) 2022.09.27
Angular - 튜토리얼04_컴포넌트  (1) 2022.09.27
Angular - 튜토리얼02  (1) 2022.09.26
Angular - 튜토리얼01  (0) 2022.09.26

    티스토리툴바

    단축키

    내 블로그

    내 블로그 - 관리자 홈 전환
    Q
    Q
    새 글 쓰기
    W
    W

    블로그 게시글

    글 수정 (권한 있는 경우)
    E
    E
    댓글 영역으로 이동
    C
    C

    모든 영역

    이 페이지의 URL 복사
    S
    S
    맨 위로 이동
    T
    T
    티스토리 홈 이동
    H
    H
    단축키 안내
    Shift + /
    ⇧ + /

    * 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.