I have a lot of import for angular components, and it looks like I can write a function to simplify the import. I just don't know how to do this, but it should be simple.
Import Samples:
import {DashboardComponent} from './app/components/dashboard/dashboard.component'; angular.module('app.components').component('dashboard', DashboardComponent); import {HeaderComponent} from './app/components/header/header.component'; angular.module('app.components').component('header', HeaderComponent);
The function below demonstrates what I want to achieve, however, I lack two concepts to make it work:
- How to put a variable (
name ) in {} ? - Is it possible to use angular filter in functions like
| ucfirst | ucfirst in a | ucfirst file?
componentImporter('header'); function componentImporter(name) { import {name | ucfirst + 'Component'} from './app/components/'+ name + '/' + name +'.component'; angular.module('app.components').component(name, name | ucfirst + 'Component'); }
Finally, I encountered an error:
'import' and 'export' can only be displayed at the top level
So can this ever work?
angularjs ecmascript-6
Iannazzi
source share