javascript - Displaying user specific data with ng-repeat in AngularJS -
i'm trying allow logged in users save links. want links display in array when user logged in. here code.
js
app.controller('commentctrl', function($scope, $firebase, firebase_url, auth) { var saveref = new firebase(firebase_url); var savesync = $firebase(saveref); $scope.savelater = savesync.$asarray(); $scope.saveit = function(item, link, saver) { $scope.savelater.$add({item: $scope.item.title, link: $scope.item.link, saver: auth.user.email}); }; )};
html
<button ng-disabled="!signedin()" ng-click="saveit(save)"</button> <div ng-repeat="save in savelater" ng-hide="!signedin()"> <a href="{{save.link}}" ng-show="auth.user.email === save.saver">{{save.item}} </a> </div>
i've tried number of different ways. none have provided me luck. i've considered using filters, there improve way go this.
have scope variable if signed in or not checked , set when controller loaded.
$scope.signedin = signedin();//when controller loaded returns true or false
then set ng-disabled value on variable.
<button ng-disabled="!signedin" ng-click="saveit(save)"</button>
if want check if signed in multiple scopes or something, have ng-init set scope value "signedin" variable on scope.
also, "save" not available if outside ng-repeat. angular like, "which save? ...what?" every repeated item there "save" available, , want 1 of them.
if don't want "saveit" button within ng-repeat have value(link) available on scope, perhaps having scope variable of link save set when link want saved selected.
javascript angularjs angularjs-ng-repeat ng-repeat
No comments:
Post a Comment