Angular 2 Read More Directive

前端 未结 10 1810
一个人的身影
一个人的身影 2020-12-01 09:41

I need to build a readmore directive in Angular2. What this directive will do is for collapse and expand long blocks of text with \"Read more\" and \"Close\" links. Not on t

10条回答
  •  自闭症患者
    2020-12-01 10:09

    Again i solved these types of problem with dynamic data and full controlling.

     

    {{personalBasicModel.professionalSummary | slice:0:200}} ... {{personalBasicModel.professionalSummary }}

    Here , personalBasicModel.professionalSummary contain string . like any text.
    slice:0:200 = use slice pipe for splice string with 200 character length . you can be change length according your requirement. id="dots" & id="more" two important thing.

    Here we define a button with dynamic text (see more and see less ) with click event.

    //---------------------------------- ts file -----------------------------------//

    Define variable

    showLess_More : string = "SEE MORE...";
    paasValueOn_SeeMoreBtn : boolean = true;

    Event(Method) fire when user click on see more button

     showMore(data:boolean){
        if(data){
          $("#dots").css('display', 'none');
          $("#more").css('display', 'inline');
          this.showLess_More = "SEE LESS ...";
          this.paasValueOn_SeeMoreBtn = false;
        }else{
          $("#dots").css('display', 'inline');
          $("#more").css('display', 'none');
          this.showLess_More = "SEE MORE...";
          this.paasValueOn_SeeMoreBtn = true;
    
        }
    
      }
    

提交回复
热议问题