Skip to content

Instantly share code, notes, and snippets.

@facelordgists
Created November 1, 2018 00:02
Show Gist options
  • Save facelordgists/cea71b22281f3226ce019cd8e3889efe to your computer and use it in GitHub Desktop.
Save facelordgists/cea71b22281f3226ce019cd8e3889efe to your computer and use it in GitHub Desktop.
Angular: How to toggle a variable back and forth between two strings
a(ng-click="") toggle
var map = {
{
name: 'item1',
status: 'view'
},
{
name: 'item2',
status: 'view'
},
{
name: 'item3',
status: 'edit'
},
{
name: 'item4',
status: 'edit'
}
}
var toggleViewState = function(id){
var statuses = ['view','edit'];
map[id].status = statuses[1-statuses.indexOf(map[id].status)];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment