Skip to content

Instantly share code, notes, and snippets.

@AlphaNerd
Created April 20, 2016 11:33
Show Gist options
  • Save AlphaNerd/acc261c04bef397291941211a7eb4c6e to your computer and use it in GitHub Desktop.
Save AlphaNerd/acc261c04bef397291941211a7eb4c6e to your computer and use it in GitHub Desktop.
Like/Unlike Button - Great for using localStorage data and using a service in backend to update server.
$scope.i = 0;
$scope.likeClick = function(data){
$scope.data[$scope.i].likes.byUser = $dataservice.likeClick(data);
}
data[0] = {
headline: "SEC proposal may allow mutual funds to charge for withdrawals during periods of high volatility",
headlinelink: "http://www.bloomberg.com/news/articles/2015-09-11/fund-investors-may-pay-fees-for-withdrawals-amid-market-stress",
html_abstract: "Under a rule being considered by the SEC, mutual funds may be able to charge their investors who rush to cash out during periods of market stress, Bloomberg reports. Under current law, investors buy and sell shares at the fund's closing price. Officials at the SEC are now recommending that funds be allowed to pass on some of the trading costs they incur to meet redemptions to investors who exit. The swing pricing concept would allow funds to adjust the price that investors receive when they sell shares back to the fund. In effect, those investors would receive a price that is slightly lower than the fund's closing price. The measure, which is part of a broader rule proposal scheduled for a Sept. 22 vote, could help funds cope with shocks such as a central bank's move to increase interest rates that could prompt widespread investor withdrawals.",
id: "1438445",
name: "Wockhardt Products",
source: "Bloomberg",
the_abstract: "Under a rule being considered by the SEC, mutual funds may be able to charge their investors who rush to cash out during periods of market stress, Bloomberg reports. Under current law, investors buy and sell shares at the fund's closing price. Officials at the SEC are now recommending that funds be allowed to pass on some of the trading costs they incur to meet redemptions to investors who exit. The swing pricing concept would allow funds to adjust the price that investors receive when they sell shares back to the fund. In effect, those investors would receive a price that is slightly lower than the fund's closing price. The measure, which is part of a broader rule proposal scheduled for a Sept. 22 vote, could help funds cope with shocks such as a central bank's move to increase interest rates that could prompt widespread investor withdrawals.",
date: new Date(),
likes: {
count: 15,
byUser: false
},
comments: [{
text: "Some comment text here",
date: new Date(),
user: "id983678"
},{
text: "Some comment text here",
date: new Date(),
user: "id983678"
},{
text: "Some comment text here",
date: new Date(),
user: "id983678"
},{
text: "Some comment text here",
date: new Date(),
user: "id983678"
}],
tags: ["Bombardier, Aerospace, Nasqad"]
}
...
likeClick: function(data){
var obj = data.likes.byUser
console.log("%c*** Send Update to server:","color:red;","'like' status changed to",!obj);
//// server update code here
return !obj
},
....
<button class="button" ng-class="{'ion-ios-heart':data[i].likes.byUser,'ion-ios-heart-outline':!data[i].likes.byUser}" ng-click="likeClick(data[0])"> {{data[i].likes.count}}</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment