Skip to content

Commit

Permalink
Fixed registerControllerDecorator for Angular v1.3.
Browse files Browse the repository at this point in the history
Added a simple demo
  • Loading branch information
Marc J. Schmidt committed Nov 5, 2014
1 parent 97e8a56 commit aae933b
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 7 deletions.
2 changes: 2 additions & 0 deletions demo/Makefile
@@ -0,0 +1,2 @@
app: app.js *
traceur app.js controller/* --experimental --out build-script.js
4 changes: 4 additions & 0 deletions demo/app.js
@@ -0,0 +1,4 @@
import {registerControllerDecorator} from '../registry';

var myApp = window.angular.module('myApp', []);
registerControllerDecorator(myApp);
20 changes: 20 additions & 0 deletions 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 <marc@jarves.io>"
],
"license": "MIT",
"private": true,
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"traceur-runtime": "~0.0.72"
}
}
8 changes: 8 additions & 0 deletions demo/controller/MyController.js
@@ -0,0 +1,8 @@
import {Inject} from '../../annotations';

@Inject('$scope')
export default class MyController {
constructor($scope) {
$scope.name = 'MyController';
}
}
15 changes: 15 additions & 0 deletions demo/index.html
@@ -0,0 +1,15 @@
<!doctype html>
<html ng-app="myApp">
<head>
<meta charset="utf-8">
<title>Demo</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.1/angular.js"></script>
<script src="./bower_components/traceur-runtime/traceur-runtime.js"></script>
<script src="./build-script.js"></script>
</head>
<body>
<div ng-controller="controller/MyController">
Hi my name is {{name}}.
</div>
</body>
</html>
15 changes: 8 additions & 7 deletions 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.
Expand Down Expand Up @@ -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);
};
}]);
});
Expand Down

0 comments on commit aae933b

Please sign in to comment.