npm install
npm setup
tsc index.ts
node index.js
Created
January 16, 2016 07:46
-
-
Save podhmo/dcd6b25a2d1f0806e96a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/jquery/jquery.d.ts | |
https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/master/angularjs/angular.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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 | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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