<!DOCTYPE html>
<html>
<head>
<script data-require="angular.js@1.6.0" data-semver="1.6.0" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<heros></heros>
</body>
</html>
/* TypeScript source code
interface IHero {
id: number;
name: string;
}
const HEROS: IHero[] = [
{ id: 11, name: 'Mr. Nice' },
{ id: 12, name: 'Narco' },
{ id: 13, name: 'Bombasto' },
{ id: 14, name: 'Celeritas' },
{ id: 15, name: 'Magneta' },
{ id: 16, name: 'RubberMan' },
{ id: 17, name: 'Dynama' },
{ id: 18, name: 'Dr IQ' },
{ id: 19, name: 'Magma' },
{ id: 20, name: 'Tornado' }
];
class HerosComponentController implements ng.IComponentController {
//public static $inject: string[] = [];
public heros: IHero[];
constructor() {}
public $onInit () {
this.heros = HEROS;
}
}
class HerosComponent implements ng.IComponentOptions {
public controller: ng.Injectable<ng.IControllerConstructor>;
public controllerAs: string;
public template: string;
constructor() {
this.controller = HerosComponentController;
this.controllerAs = "$ctrl";
this.template = `
<ul>
<li ng-repeat=\"hero in $ctrl.heros\">{{ hero.name }}</li>
</ul>
`;
}
}
angular
.module("mySuperAwesomeApp", [])
.component("heros", new HerosComponent());
angular.element(document).ready(function() {
angular.bootstrap(document, ["mySuperAwesomeApp"]);
});
*/
var HEROS = [
{ id: 11, name: 'Mr. Nice' },
{ id: 12, name: 'Narco' },
{ id: 13, name: 'Bombasto' },
{ id: 14, name: 'Celeritas' },
{ id: 15, name: 'Magneta' },
{ id: 16, name: 'RubberMan' },
{ id: 17, name: 'Dynama' },
{ id: 18, name: 'Dr IQ' },
{ id: 19, name: 'Magma' },
{ id: 20, name: 'Tornado' }
];
var HerosComponentController = (function () {
function HerosComponentController() {
}
HerosComponentController.prototype.$onInit = function () {
this.heros = HEROS;
};
return HerosComponentController;
}());
var HerosComponent = (function () {
function HerosComponent() {
this.controller = HerosComponentController;
this.controllerAs = "$ctrl";
this.template = "\n <ul>\n <li ng-repeat=\"hero in $ctrl.heros\">{{ hero.name }}</li>\n </ul>\n ";
}
return HerosComponent;
}());
angular
.module("mySuperAwesomeApp", [])
.component("heros", new HerosComponent());
angular.element(document).ready(function () {
angular.bootstrap(document, ["mySuperAwesomeApp"]);
});
/* Styles go here */
A simple example of using TypeScript 2 with Angular 1