@Decorators
ECMAScript7 decorators for core Angular1.x providers
Table of Contents
- @Module
- @Requires
- @App
- @Inject
- @Service
- @ServiceFactory
- @Controller
- @Factory
- @Filter
- @ClassFactory
- @Directive
- @Component
- @DirectiveFactory
- @Provider
- @ProviderFactory
- @Constant
- @Value
- @Config
- @Run
How To
Usage
@Module
Declare angular module with given name.
Note:
@Requires
decorator has to be put next line to the@Module
.ng.IModule
instance will be passed to constructor.
TypeScript
ES5 Angular 1.x way
var DatabaseModule = angular
@Requires
Define module or provider injection requirements.
TypeScript / ES2016 way module requirements
ES5 Angular 1.x way module requirements
var DatabaseModule = angular
TypeScript / ES2016 way provider requirements
ES5 Angular 1.x way provider requirements
var DatabaseModule = angular{}DbService$inject = '$localStorate' '$resource';DatabaseModule
@App
Declare angular module with given name.
Note:
@Requires
decorator should be put next line to the@App
.- If module already defined it will be used to bootstrap aplication.
ng.IModule
instance will be passed to constructor.- If
window.$bootstrap
defined waits fot it's resolving to start bootstraping.
TypeScript
ES5 Angular 1.x way
var Application = angularangular
@Inject
Define parameter injection to constructor or function.
TypeScript / ES2016 way
ES5 Angular 1.x way
{}DbService$inject = '$localStorate' '$resource';DatabaseModule
@Service
Declare angular service with decorated class. New instance of service decorated class will be instantiated once.
TypeScript / ES2016 way
ES5 Angular 1.x way
{}DbService$inject = '$localStorate' '$resource';DatabaseModule
@ServiceFactory
Declare angular service with decorated factory method.
TypeScript / ES2016 way
ES5 Angular 1.x way
{}DbService$inject = '$localStorate' '$resource';DatabaseModule
@Controller
Declare angular with decorated class.
TypeScript / ES2016 way
ES5 Angular 1.x way
{}AppController$inject = '$localStorate' '$resource';Application
@Factory
Declare angular factory as factory method.
TypeScript / ES2016 way
ES5 Angular 1.x way
{}ConnectionFactory$inject = '$localStorate' '$resource';Application
@Filter
Declare angular filter factory with decorated factory method.
TypeScript / ES2016 way
ES5 Angular 1.x way
{}TimeFilter$inject = '$window';Application
@ClassFactory
Declare angular factory with decorated class. New instance of factory decorated class will be instantiated for each injection.
TypeScript / ES2016 way
ES5 Angular 1.x way
{}ConnectionFactory$inject = '$localStorate' '$resource';Application
@Directive
Declare angular directive with decorated class as controller.
TypeScript / ES2016 way
ES5 Angular 1.x way
{}AppComponentController$inject = '$scope';ApplicationApplication
@DirectiveFactory
Declare angular directive with decorated factory method.
TypeScript / ES2016 way
ES5 Angular 1.x way
Application
@Component
Declare angular directive with decorated class as controller.
TypeScript / ES2016 way
ES5 Angular 1.x way
{}AppComponentController$inject = '$scope';Application
@Provider
Declare angular service provider with decorated class. New instance of provider decorated class will be instantiated once.
TypeScript / ES2016 way
ES5 Angular 1.x way
{}DbProviderprototype {return this;}DbProvider$inject = '$localStorate' '$resource';DatabaseModule
@ProviderFactory
Declare angular service provider with decorated factory method.
TypeScript / ES2016 way
ES5 Angular 1.x way
{}DbProviderprototype {return this;}DbProvider$inject = '$localStorate' '$resource';DatabaseModule
@Constant
Declare angular constant provider with decorated class. Injections are unavailable for this type of providers.
TypeScript / ES2016 way
ES5 Angular 1.x way
{thisconnectionString = 'mongodb://...'}DatabaseModule
@Value
Declare angular value provider with decorated class. Injections are unavailable for this type of providers.
TypeScript / ES2016 way
ES5 Angular 1.x way
{thisconnectionString = 'mongodb://...'}DatabaseModulevalue'DbCredentilas'
@Config
Declare angular config clause with decorated class. New instance of decorated class will be instantiated inside config clause.
TypeScript / ES2016 way
ES5 Angular 1.x way
DatabaseModule
@Run
Declare angular run clause with decorated class. New instance of decorated class will be instantiated inside run clause.
TypeScript / ES2016 way
ES5 Angular 1.x way
DatabaseModule
How to use
/dist/decorators.js
file oplimized for usage with SystemJS modularizer.
I use following trick to load all registered modules.
<!-- can contains system.js and decorators.js --> <!-- can be included to concatenation of 3-p libs --> <!-- can be included to concatenation of 3-p libs -->
and this small js to start application
entry.js
// or any other Promisevar $injector = angular;var $q = $injector; var imports = ;for var defined in Systemdefined imports; // used to ensure all modules are loaded before call angular.bootstrap(...)window$bootstrap = $qallimports;
License
The MIT License (MIT)
Copyright (c)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.