angularjs - Recommend design for dynamic ionic side menu -
my app has many states falls under different categories , need different side menus each category.
/book/view /book/edit .. /dvd/buy /dvd/view ..etc i have 3 options:
1. using different menus templates:
$stateprovider .state('dvd', { url: '/dvd', abstract: true, templateurl: 'templates/dvd_menu.html', controller: 'appctrl' }) .state('book', { url: '/book', abstract: true, templateurl: 'templates/book_menu.html', controller: 'appctrl' }) using this, couldn't figure out enable button show if switch books dvds.
2. populating menu dynamically:
<ion-item menu-close ng-click="$eval(item.click)" ng-repeat="item in custommenuitems track $index"> {{item.text}} </ion-item> is solution recommended?
3. putting items in menu , switch them on , off using ng-show.
is there better solution missing, how it?
it depends on choice.
for me, creating controller can take categoryid , actionid parameters.
register in
app.js:$stateprovider .state('category', { url: '/category/:categoryid/:actionid', templateurl: 'templates/category.html', controller: 'categoryctrl' })create
categoryservicehandle items each category, example hadgetitemsmethod takescategoryid,actionid, return list of items. injectcategoryctrl:myapp.controller('categoryctrl', ['$scope', '$stateparams', 'categoryservice', function($scope, $stateparams, categoryservice){ var categoryid = $stateparams.categoryid; var actionid = $stateparams.actionid; $scope.custommenuitems = categoryservice.getitems(categoryid, actionid); });bind
custommenuitemstemplates/category.htmlview through $scope.
Comments
Post a Comment