Skip to content

Instantly share code, notes, and snippets.

@Hotell
Created June 30, 2016 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Hotell/603f356a55da7f543c0b6d40b42d9596 to your computer and use it in GitHub Desktop.
Save Hotell/603f356a55da7f543c0b6d40b42d9596 to your computer and use it in GitHub Desktop.
ngMetadata 2.x - quick start
import { Component } from 'ng-metadata/core';
@Component({
selector: 'my-app',
template: '<h1>My First Angular 1 App <small>with ng-metadata!</small></h1>'
})
export class AppComponent { }
export { AppComponent } from './app.component';
import { bootstrap } from 'ng-metadata/platform-browser-dynamic';
import { AppComponent } from './index';
bootstrap( AppComponent );
<!DOCTYPE html>
<html>
<head>
<!-- 1. Load libraries -->
<!-- Polyfill(s) for older browsers -->
<script src="https://npmcdn.com/core-js/client/shim.min.js"></script>
<script src="https://npmcdn.com/reflect-metadata@0.1.3"></script>
<script src="https://npmcdn.com/systemjs@0.19.27/dist/system.src.js"></script>
<script src="https://code.angularjs.org/1.5.7/angular.js"></script>
<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
<link rel="stylesheet" href="style.css">
</head>
<!-- 3. Display the application -->
<body>
<my-app>Loading...</my-app>
</body>
</html>
console.log('Hello World!');
/* todo: add styles */
System.config({
//use typescript for compilation
transpiler: 'ts',
typescriptOptions: {
tsconfig: true
},
meta: {
'typescript': {
"exports": "ts"
}
},
//map tells the System loader where to look for things
map: {
'app': './app',
'ng-metadata': 'https://npmcdn.com/ng-metadata',
'rxjs': 'https://npmcdn.com/rxjs@5.0.0-beta.6',
'ts': 'https://npmcdn.com/plugin-typescript@4.0.10/lib/plugin.js',
'typescript': 'https://npmcdn.com/typescript@1.9.0-dev.20160409/lib/typescript.js',
},
//packages defines our app package
packages: {
app: {
main: './main.ts',
defaultExtension: 'ts'
},
'ng-metadata': {
defaultExtension: 'js'
},
'rxjs': {
main: 'index.js',
defaultExtension: 'js'
}
}
});
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment