javascript - Angular return value from function -
i have weird situation. have following part of html:
<div><span> {{ gettitle(story.date); }}</span> </div>
now controller function:
$scope.gettitle= function (storydate) { var year = new date(storydate).getfullyear(); if (!$scope.sectiontitleyear.contains(year)) { $scope.sectiontitleyear.push(year); return year; } else { return ''; } };
and declaration of sectiontitleyear
:
$scope.sectiontitleyear = [];
now when run code, return value right one, in html empty string. whenever remove push line code. code work's fine. push line code removed:
$scope.sectiontitleyear.push(year);
please advise me do.
you return year if it's not in $scope.sectiontitleyear
, of course work if remove line - prevent year being pushed array.
if after remove line code working, perhaps should return year, this:
$scope.gettitle= function (storydate) { var year = new date(storydate).getfullyear(); if (!$scope.sectiontitleyear.contains(year)) { $scope.sectiontitleyear.push(year); } return year; };
Comments
Post a Comment