하지

2016-09-23 6 views
3

나는이하지

this.legend.append('text') 
    .attr('x', legendRectSize + legendSpacing) 
    .attr('y', legendRectSize - legendSpacing) 
    .text(function(d) { return d; }); 

처럼 TS

에서 I가 파이프를 사용하려면

<text>Data will come here</text> 

등이 생성됩니다 HTML을 HTML 요소에 텍스트를 추가하는 HTML TS에 파이프를 사용하는 방법 이 데이터를 어떤 형식으로 변환하십시오. TS 코드에서 어떻게 할 수 있습니까?

나는이 HTML을 만드는 오전으로 Pipename 사용하려는 경우 다음 사용자 지정 파이프의 경우 동적으로 나는

this.legend.append('text') 
    .attr('x', legendRectSize + legendSpacing) 
    .attr('y', legendRectSize - legendSpacing) 
    .text(function(d) { return d; }).applypipe('pipename'); 
+0

질문을 명확히하십시오. 나는 네가 찾고있는 것을 이해하는 데 어려움을 겪고있다. – MorKadosh

+0

지금 괜찮습니까? @MorKadosh –

+0

완전히 타이프 코드를 추가하십시오. –

답변

3

처럼 somethig에 찾고 있어요이

<text>{{Data will come here | pipename}} </text> 

처럼 파이프를 사용할 수 없습니다 당신의 TS 파일과 동일하면 코드 아래에서 사용할 수 있습니다

import {Pipename} from './pipename'; 

Pipename.prototype.transform(arguments);//this is how u can use your custom pipe 
+0

정말 고마워요! 그것은 작동합니다! – mondayguy

6

먼저 파이프를 c omponent. 그런 다음 구성 요소에서 파이프를 사용하십시오. 이처럼 ..

pipe.ts

/** 
* filter checkbox list 
*/ 
@Pipe({ name: 'filter', pure: true }) 
export class FilterPipe{ 
    transform(items: any[], args: any): any { 
    let filter = args.toString(); 
    if(filter !== undefined && filter.length !== null){ 
     if(filter.length === 0 || items.length ===0){ 
      return items; 
     }else{ 
      return filter ? items.filter(item=> item.title.toLocaleLowerCase().indexOf(filter) != -1) : items; 
     } 
    } 
    } 
} 

component.ts (당신의 타이프 스크립트 코드에서 사용)

filterPipe = new FilterPipe(); 
fiteredArr = filterPipe.transform(chkArray,txtSearch); 

xyz.html HTML 파일에서 (사용)

<ul> 
    <li *ngFor="todo for todos | filter:'txtsearch'"> {{todo.name}} </li> 
</ul> 
+0

내 질문은 diffrenet 자바 스크립트 또는 typescript 코드 에서이 파이프를 사용하지만 html이 아닌 –

+0

내 대답은 typescript에서 파이프를 사용하고 있습니다 .. 아니, HTML에서 사용 –

+0

'순수 : true'는 기본 ... (https :// /angular.io/guide/pipes#pure-and-impure-pipes) – Guntram