Skip to content

Instantly share code, notes, and snippets.

@muhammaddadu
Created November 4, 2016 00:31
Show Gist options
  • Save muhammaddadu/85dc98ae4db9c1abaf4c44f67eb419e4 to your computer and use it in GitHub Desktop.
Save muhammaddadu/85dc98ae4db9c1abaf4c44f67eb419e4 to your computer and use it in GitHub Desktop.
Example of a function which can add views for multiple tabs easily
function traverseReplace(find, replace, object, dest) {
Object.keys(opts).forEach(function (key) {
var copy = object[key];
key = key.replace(find, replace);
if (typeof copy === 'object') {
dest[key] = {};
return traverseReplace(find, replace, copy, dest[key]);
}
if (typeof copy === 'string') {
dest[key] = copy.replace(find, replace);
}
});
}
function addForTabs(tabs, opts, provider) {
tabs.forEach(function (tabName) {
var options = {};
traverseReplace('(tab)', tabName, opts, options);
provider.state(options);
});
}
// example of how to add state for multiple tabs
addForTabs(['browse', 'home'], {
name: 'tab.(tab)-viewPicture',
url : '/(tab)/view/picture/:id',
views: {
'tab-(tab)': {
controller : 'ViewPictureController',
templateUrl: 'viewPicture/viewPicture.controller.html.tmpl'
}
}
}, $stateProvider);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment