diff --git a/demo/Makefile b/demo/Makefile new file mode 100644 index 0000000..641242d --- /dev/null +++ b/demo/Makefile @@ -0,0 +1,2 @@ +app: app.js * + traceur app.js controller/* --experimental --out build-script.js diff --git a/demo/app.js b/demo/app.js new file mode 100644 index 0000000..fd5efcb --- /dev/null +++ b/demo/app.js @@ -0,0 +1,4 @@ +import {registerControllerDecorator} from '../registry'; + +var myApp = window.angular.module('myApp', []); +registerControllerDecorator(myApp); diff --git a/demo/bower.json b/demo/bower.json new file mode 100644 index 0000000..502c410 --- /dev/null +++ b/demo/bower.json @@ -0,0 +1,20 @@ +{ + "name": "demo", + "version": "0.0.0", + "homepage": "https://github.com/marcj/angular-es6-annotations", + "authors": [ + "Marc J. Schmidt " + ], + "license": "MIT", + "private": true, + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ], + "dependencies": { + "traceur-runtime": "~0.0.72" + } +} diff --git a/demo/controller/MyController.js b/demo/controller/MyController.js new file mode 100644 index 0000000..a68cff2 --- /dev/null +++ b/demo/controller/MyController.js @@ -0,0 +1,8 @@ +import {Inject} from '../../annotations'; + +@Inject('$scope') +export default class MyController { + constructor($scope) { + $scope.name = 'MyController'; + } +} \ No newline at end of file diff --git a/demo/index.html b/demo/index.html new file mode 100644 index 0000000..1dd75c2 --- /dev/null +++ b/demo/index.html @@ -0,0 +1,15 @@ + + + + + Demo + + + + + +
+ Hi my name is {{name}}. +
+ + \ No newline at end of file diff --git a/registry.js b/registry.js index c8a71a5..4b93e7b 100644 --- a/registry.js +++ b/registry.js @@ -1,4 +1,4 @@ -import {Field, Label, Filter, Parser, Directive, Inject, InjectAsProperty} from './annotations'; +import {Filter, Parser, Directive, Inject, InjectAsProperty} from './annotations'; /** * Prepares a class constructor for angular depency injection. @@ -152,18 +152,19 @@ export function registerModuleDirective(angularModule, controller) { export function registerControllerDecorator(angularModule) { angularModule.config(function ($provide) { $provide.decorator("$controller", ['$delegate', ($delegate) => { - return function (constructor, locals) { - if (angular.isString(constructor)) { + return function (...args) { + if (angular.isString(args[0])) { try { - var moduleClass = System.get(constructor); + var moduleClass = System.get(args[0]); if (moduleClass) { - var preparedConstructor = getPreparedConstructor(System.get(constructor).default); - constructor = preparedConstructor || System.get(constructor).default; + var preparedConstructor = getPreparedConstructor(moduleClass.default); + args[0] = preparedConstructor || moduleClass.default; } } catch (e) { + throw e; } } - return $delegate(constructor, locals); + return $delegate(...args); }; }]); });