whem i am trying to call JavaScript method in html if methods parameter is null my result is method's caller scripts -


i have html code , print string js method

 <div class="commentdiv">{{ commentsubstring(item.commentlist[0].content) }} </div> 

here js method

$scope.commentsubstring = function(fullcomment)     {         var substring;         if(fullcomment.length<16 && ullcomment.length>0)             {                 substring=fullcomment;             }         if(fullcomment.length<=0 || !fullcomment)         {             substring="";         }         if(fullcomment.length>=16)         {             substring = fullcomment.substring(0,15);         }         return substring;     } 

if methods argument not null result correct, if not initialized result methods caller script

{{ commentsubstring(item.commentlist[0].content) }} 

like in picture

enter image description here

change code this:

<div class="commentdiv">{{ commentsubstring(item) }} </div> 

and:

 $scope.commentsubstring = function(item) {     if(!item || !item.commentlist[0] || !item.commentlist[0].content){         return "";     }     var fullcomment = item.commentlist[0].content;         if(fullcomment.length>=16) {             fullcomment = fullcomment.substring(0,15);         }     return fullcomment; } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -