javascript - Best Practices: Should I use ng-switch for this? -


i've got object in angular.

$scope.columns = {     workspace: {         title: "workspace",         type: "workspace",         activities: []     },     alerts: {         title: "alerts",         type: "alert",         activities: []     },     main: {         title: "main feed",         type: "main",         activities: []     } }; 

and in html need loop through dynamically create series of columns in app (think trello)

each type reference custom directive.

i'm trying figure out best way place directives.

based on data, code below appropriate way handle dynamically creating these?

<div ng-repeat="(key, obj) in columns">      <div ng-switch on="obj.type">         <workspace-feed ng-switch-when="workspace" />         <alert-feed ng-switch-when="alert" />         <main-feed ng-switch-when="main" />         <filter-feed ng-switch-when="filter" />     </div>  </div> 

i'd love able like... <{{obj.type}}-feed /> i'm not sure if valid, or if there's better way create this.

thoughts appreciated!

what have far looks fine.

depending on how different columns are, may opt use 1 directive dynamically loads template instead of multiple directives. example, take @ ng-include:

<div ng-include="'columns/' + column.type + '.html'"></div> 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -