javascript - AngularJS string is not a function -
to shorten post info needed problem, made button gives +1 rating , button -1 rating when clicked , html code,
<p> <strong>rating: </strong> {{ album.rating }} <button class="btn btn-small" ng-click="upvoterating(album)">+</button> <button class="btn btn-small" ng-click="downvoterating(album)">-</button> </p>
nothing unusual, heres angularjs code using scope , function button.
$scope. upvoterating = 'upvoterating'; $scope. downvoterating = 'downvoterating'; function upvoterating(album) { album.rating++; } function downvoterating(album) { if (album.rating > 0) album.rating--; }
so theres no problem code guessings everytime click button on page, says on console:
"typeerror: string not function @ http://localhost:1234/lib/angular/angular.min.js:168:37 @ http://localhost:1234/lib/angular/angular.min.js:186:167 @ g.$eval (http://localhost:1234/lib/angular/angular.min.js:104:308) @ g.$apply (http://localhost:1234/lib/angular/angular.min.js:105:48) @ htmlbuttonelement.o.event.dispatch (http://localhost:1234/lib/jquery-2.1.0.min.js:3:6055) @ htmlbuttonelement.r.handle (http://localhost:1234/lib/jquery-2.1.0.min.js:3:2830) angular.js:9507"
i've got no idea how fix this, i've been looking hour, please, if need more code out find problem out ask right away!
thanks again!
you're setting string here:
$scope.upvoterating = 'upvoterating';
and trying call function here
<button class="btn btn-small" ng-click="upvoterating(album)">+</button>
remove quotes in controller , should good:
$scope.upvoterating = upvoterating; $scope.downvoterating = downvoterating;
Comments
Post a Comment