https://github.com/paragdiwan/ng-ts
Angular Controller using Typescript
https://github.com/paragdiwan/ng-ts
angular html javascript typescript
Last synced: 2 months ago
JSON representation
Angular Controller using Typescript
- Host: GitHub
- URL: https://github.com/paragdiwan/ng-ts
- Owner: paragdiwan
- Created: 2017-05-20T14:58:53.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-22T18:41:26.000Z (about 9 years ago)
- Last Synced: 2025-12-28T15:07:09.058Z (6 months ago)
- Topics: angular, html, javascript, typescript
- Language: TypeScript
- Homepage:
- Size: 405 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ng-ts
Angular Controller using Typescript
---------------
- This is an attempt to create a Angular 1.x controller using Typescript.
- This controller demonstrates usuage of '$http' service.
- Angular controller is being mapped to Typescript Class and interfaces enforces that
we define models , actions that are implemented by a controller class.
All you need is to paste the entire folder in 'webroot' and run index.html.
Snippet
--------
```javascript
module MyApplication {
/**
* An interface enforces that we expose appropriate models and actions required
* on these models to the Controller.
*/
export interface IMessage {
displayText: string;
flag: boolean;
serviceResponse: any;
changeScopeModel(): void;
}
/**
* A Controller class that exposes models via member variables and methods.
*/
export class DemoMVVMCtrl implements IMessage {
displayText: string; // Demo MV on the UI.
flag: boolean; // Toggle switch
serviceResponse: any; // Demo Service response model.
static $inject = ['dataAccessService'];
constructor(private dataAccessService: common.services.DataAccessService) {
this.displayText = "Welcome to Typescript";
this.flag = true;
}
changeScopeModel() {
this.flag = !this.flag;
if (this.flag) {
this.displayText = "You are loving TS."
}
else {
this.displayText = "Welcome to Typescript";
}
}
/**
* Talks to remote service to get data.
*/
getDataFromService() {
try {
this.dataAccessService.getDataFromResource().then((response) => {
try {
this.serviceResponse = response.data;
}
catch (exception) {
throw exception;
}
})
}
catch (exception) {
throw exception;
}
}
}
// Create a model along with Service dependency & Register a controller.
angular.module('app', ['common.services'])
.controller("DemoMVVMCtrl", MyApplication.DemoMVVMCtrl);
}
```