Angular-Ecmascript
angular-ecmascript
is a utility library which will help you write an AngularJS app using ES6
's class system.
As for now there is no official way to do so, however using ES6
syntax is recommended, hence this library was created.
In addition, angular-ecmascript
provides us with some very handy features, like auto-injection without using any pre-processors like ng-annotate. For more information about angular-ecmascript
's API and features please read the following docs.
Docs
angular-ecmascript
provides us with some base module-helpers
classes which we should inherit from while writing our helpers. These are the available helpers:
Each helper can be defined with a static $inject
property which will be responsible for dependencies injection, and a static $name
property, which is responsible for specifying the helper's name and defaults to the class'es name.
; static $name = '$date' { return ; } static $inject = '$date' { super...args; thiscreatedAt = this$date; }
To interface with these helpers we will need to use a module-loader
provided by angular-ecmascript
. Just create a new AngularJS
module wrapped by the loader and use it like so:
// libs;;// module-helpers;;; // appApp = Angular; // loaderApp ;
Loader()
can take a module name as the first argument and an optional dependencies array if you'd like to load a module by name.Loader.load()
can take an array of several module-helpers instead of chaining them one-by-one.Loader.load()
can take a string as the first argument representing the provider type and its value as the second argument, just like the $provide service.
Provider
Used to define a new provider.
; static $name = '$now' return ;
Service
Used to define a new service.
; static $name = '$date' { return ; }
Factory
Used to define a new factory
.
- Note that the
create
method must be implemented, otherwise an error will be thrown during load time.
; static $name = 'now' { return ; }
Controller
Used to define a new controller.
$scope
will be injected automatically so no need to specify it.- When using angular-meteor the controller will be set as the view model automatically.
; { super...args; thiscreatedAt = ; } { console; }
Directive
Used to define a new directive.
; templateUrl: 'my-template.html' restrict = 'E' transclude = true scope = {} { scopefoo = 'foo'; scopebar = 'bar'; }
Decorator
Used to define a new decorator.
$delegate
will be injected automatically so no need to specify it.- Note that the
decorate
method must be implemented, otherwise an error will be thrown during load time. - No need to return the
$delegate
object, it should be handled automatically.
; static $name = 'myService' { // an additional fn to add to the service } { this$delegateaHelpfulAddition = thishelperFn; }
Filter
Used to define a new filter.
- Note that the
filter
method must be implemented, otherwise an error will be thrown during load time.
; { let out = ''; for let i = 0; i < inputlength; i++ out = input + out; // conditional based on optional argument if uppercase out = out; return out; }
Config
Used to define a new config
.
- Note that the
configure
method must be implemented, otherwise an error will be thrown during load time.
; static $inject = '$routeProvider' { super...args; thisfetchUser = 'http' this::thisfetchUser; } { this$routeProvider ; } { return $http; }
Runner
Used to define a new run block
.
- Note that the
run
method must be implemented, otherwise an error will be thrown during load time.
; static $inject = '$rootScope' '$state' { this$rootScope; }
Download
The source is available for download from GitHub. Alternatively, you can install using Node Package Manager (npm
):
npm install angular-ecmascript