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
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
Post a Comment