반응형

옵션

설명
bindingPropertyName

데코레이터는 클레스의 필드에 입력 속성으로 마킹하는 기능을 하며 메타데이터 구성을 제공합니다. 바인딩된 데이터의 입력 속성을 명시하면 앵귤러는 자동적으로 값을 업데이트 합니다.

옵션

데코레이터는 클레스의 필드에 입력 속성으로 마킹하는 기능을 하며 메타데이터 구성을 제공합니다. 바인딩된 데이터의 입력 속성을 명시하면 앵귤러는 자동적으로 값을 업데이트 합니다.

bindingPropertyName: string

컴포넌트가 인스턴스화 할 때, 템플릿에서 마음껏 다른 이름을 사용할 수 있도록 바인드 속성의 이름을 맵핑합니다.

기본적으로, 바인드된 속성의 원래 이름이 입력 바인딩을 위해서 사용됩니다.

아래 예제에서 2개의 입력 속성을 갖는 컴포넌트를 만들었습니다, 1개는 특별한 바인딩 이름을 갖습니다.

  1. @Component({
  2. selector: 'bank-account',
  3. template: `
  4. Bank Name: {{bankName}}
  5. Account Id: {{id}}
  6. `
  7. })
  8. class BankAccount {
  9. // 이 속성은 바운드된 본래의 이름을 사용합니다.
  10. @Input() bankName: string;
  11. // 템플릿에서 이 컴포넌트가 인스턴스화 될 때
  12. // 이 속성 값은 다른 속성 이름으로 바운드 됩니다.
  13. @Input('account-id') id: string;
  14.  
  15. // 이 속성은 바운드되지 않으며, 앵귤러가 자동적으로 업데이트할 수 없습니다.
  16. normalizedBankName: string;
  17. }
  18.  
  19. @Component({
  20. selector: 'app',
  21. template: `
  22. <bank-account bankName="RBC" account-id="4747"></bank-account>
  23. `
  24. })
  25.  
  26. class App {}


반응형

'프로그래밍 > Angular' 카테고리의 다른 글

FormsModule With ViewChild  (0) 2018.09.05
Component- Event  (0) 2018.08.12
Component- DataBinding  (0) 2018.08.11
Pipe  (0) 2018.06.07
NgModules  (0) 2018.06.07
반응형

@Input() - angular/core (컴포넌트 데이터 바인딩)


public으로 외부 컴포넌트에서 접근할 수 있도록 도와주는 데코레이터


parent component.ts

componentElements = [{type: 'example', name: 'Testexample', content: 'Just a test!'}];


parent component.html

<app-component-element
*ngFor="let componentElement of componentElements"
[customPropertyName]="componentElement"></app-component-element>

html에서는 []를 이용하여 속성으로 접근. 


component.ts
import { Input } from '@angular/core';

@Input('customPropertyName') element : {type: string, name: string, content: string};

(component.ts의 데코레이터 변수명(element)에 따라 데코레이터의 패러미터를 달리 할 수 있음.

속성명과 @Input 데코레이터의 변수명이 다를경우: @Input('customPropertyName') element: {}

속성명과 @Input 데코레이터의 변수명이 같은경우: @Input() element: {} 


component.html

<div class="panel panel-default">
<div class="panel-heading">{{ element.name }}</div>
<div class="panel-body">
<p>
<strong *ngIf="element.type === 'example'" style="color: red">{{ element.content }}</strong>
</p>
</div>
</div>



응용한 예제 보기


API 보기 (블로그, 원본)

반응형

'프로그래밍 > Angular' 카테고리의 다른 글

FormsModule With ViewChild  (0) 2018.09.05
Component- Event  (0) 2018.08.12
Input decoretor  (0) 2018.08.12
Pipe  (0) 2018.06.07
NgModules  (0) 2018.06.07
반응형

모든 어플리케이션은 간단한 작업을로 시작합니다: 데이터를 받고, 변형시키고, 사용자에게 보여주는 기능입니다.

얻은 데이터는 생성하기 간편한 지역변수 이거나 스트리밍하는 복잡한 데이터로 웹 소캣 위 에서 가능합니다.


data가 도착하면, 그 값을 곧바로 view에 직접 toString 값으로  넣을 수 있는데, 드물지만 이러한 작업은 가끔 좋은 UX를 제공하곤합니다.

예를 들자면, 대부분의 사용 방법으로, 

사용자가 날짜를 April 16, 1988과 같은 간단한 양식을 

Fri Apr 15 1988 00:00:00 GMT-0700 (Pacific Daylight Time) 처럼 보길 좋아하지 않습니다.


많은 어플리케이션을 반복적으로 같은 변경을 적용할 경우에 사용할 수 있습니다.
이러한 작업을 스타일처럼  사용할 수 있습니다. 실제로, HTML 템플릿으로 style처럼 사용할 수 있습니다.


앵귤러 pipe를 소개하자면, display-value를 변경시켜 쓰는 방식으로 HTML에 선언하여 사용할 수 있습니다.


live example / download example 으로 실행해 볼 수 있으며, Stackblitz나 download를 할 수 있습니다.


사용 하기

pipe는 데이터를 input 으로 받아 원하는 형태로 변환 시켜 표현할 수 있습니다. 
이 페이지에서, 컴포넌트의 birthday 속성을 통해 사람이 보기 편한 날짜 형식으로 변경하는 pipe를 사용하게 됩니다.

src/app/hero-birthday1.component.ts
import { Component } from '@angular/core';

@Component({
  selector: 'app-hero-birthday',
  template: `<p>The hero's birthday is {{ birthday | date }}</p>`
})
export class HeroBirthdayComponent {
  birthday = new Date(1988, 3, 15); // April 15, 1988
}

컴포넌트의 템플릿에 주목해 보겠습니다.


src/app/app.component.html
<p>The hero's birthday is {{ birthday | date }}</p>

{{ }} 표현 안쪽을 보면, 컴포넌트의 birthday 값이 pipe 연산자 ( | )를 통해 오른쪽에 있는 Date pipe 함수로 흘러갑니다.

모든 pipe는 이러한 방식으로 작동합니다.


제공하는(built-in) pipe


앵귤러는  DatePipeUpperCasePipeLowerCasePipeCurrencyPipe, 그리고 PercentPipe 와 같은 파이프를 갖고 있습니다.

모두 어떤 템플릿에서든지 사용 가능합니다.



다른 pipe를 좀 더 알고 싶다면 API 레퍼런스의 pipes topics를 참고하세요. "pipe" 단어를 포함하는 것을 필터링 해보세요.

앵귤러는 FilterPipe OrderByPipe를 갖고 있지 않는 이유를 앵귤러 페이지 Appendix에 설명해 놓았습니다.



반응형

'프로그래밍 > Angular' 카테고리의 다른 글

FormsModule With ViewChild  (0) 2018.09.05
Component- Event  (0) 2018.08.12
Input decoretor  (0) 2018.08.12
Component- DataBinding  (0) 2018.08.11
NgModules  (0) 2018.06.07

+ Recent posts