Created
November 4, 2016 00:31
-
-
Save muhammaddadu/85dc98ae4db9c1abaf4c44f67eb419e4 to your computer and use it in GitHub Desktop.
Example of a function which can add views for multiple tabs easily
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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