javascript - Dynamicly include directive in angular -
i have situation dynamically include directives/components angular template. reason why want i'm writing dashboard should easy extend new widgets. directive/component thinking in angular , prefer able make directive of each widget. add each widget ng-repeat or similiar. make easy add new widgets on time. questions first of if thinking sound , secondly if know if has written can start with.
example
vm.widgets = [{ component: 'widgeta' },{ component: 'widgetb' }] <div ng-repeat="widget in dashboard.widgets"> <ng-include-component name="widget.component"> </div>
something worked me:
your view:
<div ng-repeat="row in components"> <div class="row"> <div ng-repeat="col in row"> <div class="col-md-{{col.width}}" ng-include="col.url"/> </div> </div> </div> your controller:
$scope.components = { 'row1': [ [{ url: '/views/widget1.html', width: '4' }, { url: '/views/widget2.html', width: '8' }] ], 'row2': [ [{ url: '/views/widget3.html', width: '4' }, { url: '/views/widget4.html', width: '4' }, { url: 'views/widget5.html', width: '4' }] ] };
Comments
Post a Comment