How to use pipe in ts not HTML









up vote
7
down vote

favorite
3












I adding text into html element from ts



like this



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


this will create html like



<text>Data will come here</text>


I want to use pipe to convert this data into some form
how can I do that from ts code ?



and as I am creating this HTML dynamically I cannot use pipe like this



<text>Data will come here </text>


I am looking for somethig like



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









share|improve this question























  • Please clarify your question. I'm having hard times understanding what your'e looking for.
    – MorKadosh
    Sep 23 '16 at 6:06










  • is this fine now ? @MorKadosh
    – Arun Tyagi
    Sep 23 '16 at 6:24










  • please add your fully typescript code.
    – Bharat Chauhan
    Sep 23 '16 at 6:45














up vote
7
down vote

favorite
3












I adding text into html element from ts



like this



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


this will create html like



<text>Data will come here</text>


I want to use pipe to convert this data into some form
how can I do that from ts code ?



and as I am creating this HTML dynamically I cannot use pipe like this



<text>Data will come here </text>


I am looking for somethig like



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









share|improve this question























  • Please clarify your question. I'm having hard times understanding what your'e looking for.
    – MorKadosh
    Sep 23 '16 at 6:06










  • is this fine now ? @MorKadosh
    – Arun Tyagi
    Sep 23 '16 at 6:24










  • please add your fully typescript code.
    – Bharat Chauhan
    Sep 23 '16 at 6:45












up vote
7
down vote

favorite
3









up vote
7
down vote

favorite
3






3





I adding text into html element from ts



like this



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


this will create html like



<text>Data will come here</text>


I want to use pipe to convert this data into some form
how can I do that from ts code ?



and as I am creating this HTML dynamically I cannot use pipe like this



<text>Data will come here </text>


I am looking for somethig like



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









share|improve this question















I adding text into html element from ts



like this



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


this will create html like



<text>Data will come here</text>


I want to use pipe to convert this data into some form
how can I do that from ts code ?



and as I am creating this HTML dynamically I cannot use pipe like this



<text>Data will come here </text>


I am looking for somethig like



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






javascript angular pipe






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 23 '16 at 6:23

























asked Sep 23 '16 at 6:04









Arun Tyagi

75121025




75121025











  • Please clarify your question. I'm having hard times understanding what your'e looking for.
    – MorKadosh
    Sep 23 '16 at 6:06










  • is this fine now ? @MorKadosh
    – Arun Tyagi
    Sep 23 '16 at 6:24










  • please add your fully typescript code.
    – Bharat Chauhan
    Sep 23 '16 at 6:45
















  • Please clarify your question. I'm having hard times understanding what your'e looking for.
    – MorKadosh
    Sep 23 '16 at 6:06










  • is this fine now ? @MorKadosh
    – Arun Tyagi
    Sep 23 '16 at 6:24










  • please add your fully typescript code.
    – Bharat Chauhan
    Sep 23 '16 at 6:45















Please clarify your question. I'm having hard times understanding what your'e looking for.
– MorKadosh
Sep 23 '16 at 6:06




Please clarify your question. I'm having hard times understanding what your'e looking for.
– MorKadosh
Sep 23 '16 at 6:06












is this fine now ? @MorKadosh
– Arun Tyagi
Sep 23 '16 at 6:24




is this fine now ? @MorKadosh
– Arun Tyagi
Sep 23 '16 at 6:24












please add your fully typescript code.
– Bharat Chauhan
Sep 23 '16 at 6:45




please add your fully typescript code.
– Bharat Chauhan
Sep 23 '16 at 6:45












4 Answers
4






active

oldest

votes

















up vote
10
down vote













First import your pipe in component. And then use your pipe in your component. Like this..



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)




component.ts (Use in your typescript code)



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


xyz.html (Use in your html file)



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





share|improve this answer






















  • my question is diffrenet how to use this pipe in javascript or typescript code but not in html
    – Arun Tyagi
    Sep 23 '16 at 6:34











  • my answer is also use pipe in typescript..Not, use in HTML
    – Bharat Chauhan
    Sep 23 '16 at 6:42











  • pure: true is default... (angular.io/guide/pipes#pure-and-impure-pipes)
    – Guntram
    Nov 30 '17 at 9:53


















up vote
7
down vote













If Pipename is your custom pipe then if you want to use the same in your ts file then you can use below code



import Pipename from './pipename';

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





share|improve this answer




















  • thank you so much! it works!
    – mondayguy
    Sep 4 '17 at 18:45










  • that is exactly what i was looking for
    – Gregfr
    Mar 15 at 11:16










  • You would circumvent the constructor though, if that were used in the pipe Class, and who knows what @Pipe might add?
    – TrySpace
    Apr 4 at 17:40


















up vote
1
down vote













In .ts



import YourPipe from '/';



let value = new YourPipe().transform(param);






share|improve this answer



























    up vote
    0
    down vote













    import pipe in the component



    import PipeName from './pipename'


    include it in the provides



    @Component(
    selector: 'pipe-using-component',
    templateUrl: './pipe-using-component.html',
    providers: [
    PipeName
    ],
    )


    inject it in the constructor



    export class PipeUsingComponent 
    constructor(private pipeName: PipeName)


    var requiredResult = this.pipeName.transform(passvalue);
    }





    share|improve this answer








    New contributor




    R.C.VISHNU Vardhan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.

















      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f39653630%2fhow-to-use-pipe-in-ts-not-html%23new-answer', 'question_page');

      );

      Post as a guest






























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      10
      down vote













      First import your pipe in component. And then use your pipe in your component. Like this..



      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)




      component.ts (Use in your typescript code)



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


      xyz.html (Use in your html file)



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





      share|improve this answer






















      • my question is diffrenet how to use this pipe in javascript or typescript code but not in html
        – Arun Tyagi
        Sep 23 '16 at 6:34











      • my answer is also use pipe in typescript..Not, use in HTML
        – Bharat Chauhan
        Sep 23 '16 at 6:42











      • pure: true is default... (angular.io/guide/pipes#pure-and-impure-pipes)
        – Guntram
        Nov 30 '17 at 9:53















      up vote
      10
      down vote













      First import your pipe in component. And then use your pipe in your component. Like this..



      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)




      component.ts (Use in your typescript code)



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


      xyz.html (Use in your html file)



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





      share|improve this answer






















      • my question is diffrenet how to use this pipe in javascript or typescript code but not in html
        – Arun Tyagi
        Sep 23 '16 at 6:34











      • my answer is also use pipe in typescript..Not, use in HTML
        – Bharat Chauhan
        Sep 23 '16 at 6:42











      • pure: true is default... (angular.io/guide/pipes#pure-and-impure-pipes)
        – Guntram
        Nov 30 '17 at 9:53













      up vote
      10
      down vote










      up vote
      10
      down vote









      First import your pipe in component. And then use your pipe in your component. Like this..



      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)




      component.ts (Use in your typescript code)



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


      xyz.html (Use in your html file)



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





      share|improve this answer














      First import your pipe in component. And then use your pipe in your component. Like this..



      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)




      component.ts (Use in your typescript code)



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


      xyz.html (Use in your html file)



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






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Sep 23 '16 at 6:52

























      answered Sep 23 '16 at 6:30









      Bharat Chauhan

      1,38912233




      1,38912233











      • my question is diffrenet how to use this pipe in javascript or typescript code but not in html
        – Arun Tyagi
        Sep 23 '16 at 6:34











      • my answer is also use pipe in typescript..Not, use in HTML
        – Bharat Chauhan
        Sep 23 '16 at 6:42











      • pure: true is default... (angular.io/guide/pipes#pure-and-impure-pipes)
        – Guntram
        Nov 30 '17 at 9:53

















      • my question is diffrenet how to use this pipe in javascript or typescript code but not in html
        – Arun Tyagi
        Sep 23 '16 at 6:34











      • my answer is also use pipe in typescript..Not, use in HTML
        – Bharat Chauhan
        Sep 23 '16 at 6:42











      • pure: true is default... (angular.io/guide/pipes#pure-and-impure-pipes)
        – Guntram
        Nov 30 '17 at 9:53
















      my question is diffrenet how to use this pipe in javascript or typescript code but not in html
      – Arun Tyagi
      Sep 23 '16 at 6:34





      my question is diffrenet how to use this pipe in javascript or typescript code but not in html
      – Arun Tyagi
      Sep 23 '16 at 6:34













      my answer is also use pipe in typescript..Not, use in HTML
      – Bharat Chauhan
      Sep 23 '16 at 6:42





      my answer is also use pipe in typescript..Not, use in HTML
      – Bharat Chauhan
      Sep 23 '16 at 6:42













      pure: true is default... (angular.io/guide/pipes#pure-and-impure-pipes)
      – Guntram
      Nov 30 '17 at 9:53





      pure: true is default... (angular.io/guide/pipes#pure-and-impure-pipes)
      – Guntram
      Nov 30 '17 at 9:53













      up vote
      7
      down vote













      If Pipename is your custom pipe then if you want to use the same in your ts file then you can use below code



      import Pipename from './pipename';

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





      share|improve this answer




















      • thank you so much! it works!
        – mondayguy
        Sep 4 '17 at 18:45










      • that is exactly what i was looking for
        – Gregfr
        Mar 15 at 11:16










      • You would circumvent the constructor though, if that were used in the pipe Class, and who knows what @Pipe might add?
        – TrySpace
        Apr 4 at 17:40















      up vote
      7
      down vote













      If Pipename is your custom pipe then if you want to use the same in your ts file then you can use below code



      import Pipename from './pipename';

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





      share|improve this answer




















      • thank you so much! it works!
        – mondayguy
        Sep 4 '17 at 18:45










      • that is exactly what i was looking for
        – Gregfr
        Mar 15 at 11:16










      • You would circumvent the constructor though, if that were used in the pipe Class, and who knows what @Pipe might add?
        – TrySpace
        Apr 4 at 17:40













      up vote
      7
      down vote










      up vote
      7
      down vote









      If Pipename is your custom pipe then if you want to use the same in your ts file then you can use below code



      import Pipename from './pipename';

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





      share|improve this answer












      If Pipename is your custom pipe then if you want to use the same in your ts file then you can use below code



      import Pipename from './pipename';

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






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Sep 23 '16 at 6:27









      sudheer KB

      1,122618




      1,122618











      • thank you so much! it works!
        – mondayguy
        Sep 4 '17 at 18:45










      • that is exactly what i was looking for
        – Gregfr
        Mar 15 at 11:16










      • You would circumvent the constructor though, if that were used in the pipe Class, and who knows what @Pipe might add?
        – TrySpace
        Apr 4 at 17:40

















      • thank you so much! it works!
        – mondayguy
        Sep 4 '17 at 18:45










      • that is exactly what i was looking for
        – Gregfr
        Mar 15 at 11:16










      • You would circumvent the constructor though, if that were used in the pipe Class, and who knows what @Pipe might add?
        – TrySpace
        Apr 4 at 17:40
















      thank you so much! it works!
      – mondayguy
      Sep 4 '17 at 18:45




      thank you so much! it works!
      – mondayguy
      Sep 4 '17 at 18:45












      that is exactly what i was looking for
      – Gregfr
      Mar 15 at 11:16




      that is exactly what i was looking for
      – Gregfr
      Mar 15 at 11:16












      You would circumvent the constructor though, if that were used in the pipe Class, and who knows what @Pipe might add?
      – TrySpace
      Apr 4 at 17:40





      You would circumvent the constructor though, if that were used in the pipe Class, and who knows what @Pipe might add?
      – TrySpace
      Apr 4 at 17:40











      up vote
      1
      down vote













      In .ts



      import YourPipe from '/';



      let value = new YourPipe().transform(param);






      share|improve this answer
























        up vote
        1
        down vote













        In .ts



        import YourPipe from '/';



        let value = new YourPipe().transform(param);






        share|improve this answer






















          up vote
          1
          down vote










          up vote
          1
          down vote









          In .ts



          import YourPipe from '/';



          let value = new YourPipe().transform(param);






          share|improve this answer












          In .ts



          import YourPipe from '/';



          let value = new YourPipe().transform(param);







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jun 5 at 6:38









          Zoha Irshad

          1413




          1413




















              up vote
              0
              down vote













              import pipe in the component



              import PipeName from './pipename'


              include it in the provides



              @Component(
              selector: 'pipe-using-component',
              templateUrl: './pipe-using-component.html',
              providers: [
              PipeName
              ],
              )


              inject it in the constructor



              export class PipeUsingComponent 
              constructor(private pipeName: PipeName)


              var requiredResult = this.pipeName.transform(passvalue);
              }





              share|improve this answer








              New contributor




              R.C.VISHNU Vardhan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.





















                up vote
                0
                down vote













                import pipe in the component



                import PipeName from './pipename'


                include it in the provides



                @Component(
                selector: 'pipe-using-component',
                templateUrl: './pipe-using-component.html',
                providers: [
                PipeName
                ],
                )


                inject it in the constructor



                export class PipeUsingComponent 
                constructor(private pipeName: PipeName)


                var requiredResult = this.pipeName.transform(passvalue);
                }





                share|improve this answer








                New contributor




                R.C.VISHNU Vardhan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.



















                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  import pipe in the component



                  import PipeName from './pipename'


                  include it in the provides



                  @Component(
                  selector: 'pipe-using-component',
                  templateUrl: './pipe-using-component.html',
                  providers: [
                  PipeName
                  ],
                  )


                  inject it in the constructor



                  export class PipeUsingComponent 
                  constructor(private pipeName: PipeName)


                  var requiredResult = this.pipeName.transform(passvalue);
                  }





                  share|improve this answer








                  New contributor




                  R.C.VISHNU Vardhan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  import pipe in the component



                  import PipeName from './pipename'


                  include it in the provides



                  @Component(
                  selector: 'pipe-using-component',
                  templateUrl: './pipe-using-component.html',
                  providers: [
                  PipeName
                  ],
                  )


                  inject it in the constructor



                  export class PipeUsingComponent 
                  constructor(private pipeName: PipeName)


                  var requiredResult = this.pipeName.transform(passvalue);
                  }






                  share|improve this answer








                  New contributor




                  R.C.VISHNU Vardhan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  share|improve this answer



                  share|improve this answer






                  New contributor




                  R.C.VISHNU Vardhan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered yesterday









                  R.C.VISHNU Vardhan

                  11




                  11




                  New contributor




                  R.C.VISHNU Vardhan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  R.C.VISHNU Vardhan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  R.C.VISHNU Vardhan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f39653630%2fhow-to-use-pipe-in-ts-not-html%23new-answer', 'question_page');

                      );

                      Post as a guest














































































                      Popular posts from this blog

                      Top Tejano songwriter Luis Silva dead of heart attack at 64

                      政党

                      天津地下鉄3号線