Skip to content

Instantly share code, notes, and snippets.

@podhmo
Created January 16, 2016 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save podhmo/dcd6b25a2d1f0806e96a to your computer and use it in GitHub Desktop.
Save podhmo/dcd6b25a2d1f0806e96a to your computer and use it in GitHub Desktop.
npm install
npm setup
tsc index.ts
node index.js
https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/jquery/jquery.d.ts
https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/angularjs/angular.d.ts
/// <reference path="./angular.d.ts" />
interface MySetupFunction {
(callback: (angular: ng.IAngularStatic) => void): void;
}
declare var require: (module: string) => any;
const setup: MySetupFunction = require("./setup");
setup((angular: ng.IAngularStatic) => {
const app = angular.module("app", []);
// registering config
app.value("config", "this is config");
// registering service that using the config registered
class GreetingService {
constructor(private config: {name: string}) {
}
greeting(message: string) {
// actually, this.config: string. (see: app.value("config") ...)
return `${this.config.name}: ${message}`;
}
}
GreetingService.$inject = ["config"];
app.service("GreetingService", GreetingService);
const injector: ng.auto.IInjectorService = angular.injector(["ng", "app"]);
const greeting = injector.get<GreetingService>("GreetingService");
console.log(greeting.greeting("hello"));
// undefined: hello
});
{
"name": "fragile-di",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"angular": "^1.4.8",
"typescript": "^1.7.3",
"benv": "^3.0.0",
"angular-messages": "~1.4.8"
},
"scripts": {
"download": "wget -i d.ts.list",
"normalize.d.ts": "gsed -i 's@../jquery/@./@' angular.d.ts",
"setup": "npm run download && npm run normalize.d.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
'use strict';
var benv = require('benv');
function setup(cb){
benv.setup(function(){
global.Node = window.Node;
benv.expose({
angular: benv.require(require.resolve("angular/angular"), "angular")
});
cb(window.angular);
});
}
module.exports = setup;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment