Last active
August 23, 2018 13:45
-
-
Save andreasderuiter/12711103380d6e0a5c69 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
module App { | |
"use strict"; | |
interface IMyAppController { | |
values: string[]; | |
errorMessage: string; | |
isVisibleErrorMessage: boolean | |
} | |
export class MyAppController implements IMyAppController { | |
errorMessage: string = ""; | |
isVisibleErrorMessage: boolean = false; | |
values: string[] = []; | |
static $inject: string[] = ["$http", "$window"]; | |
constructor(private $http: ng.IHttpService, private $window: ng.IWindowService) { | |
this.getValues(); | |
} | |
private getValues(): void { | |
this.$http.get("/api/sample") | |
.then((response: ng.IHttpPromiseCallbackArg<string[]>) => { | |
this.isVisibleErrorMessage = false; | |
this.values = response.data; | |
}) | |
.catch(((reason: ng.IHttpPromiseCallbackArg<string[]>) => { | |
this.isVisibleErrorMessage = true; | |
this.errorMessage = reason.statusText; | |
} | |
return this.values; | |
})); | |
} | |
} | |
angular.module("app").controller("MyAppController", MyAppController); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actually, I think the correct version of this file is this:
module App {
"use strict";
interface IMyAppController {
values: string[];
errorMessage: string;
isVisibleErrorMessage: boolean
}
export class MyAppController implements IMyAppController {
$onInit = () => { }; // this was missing and it's required ( at least, to make this file ready to compile )
errorMessage: string = "";
isVisibleErrorMessage: boolean = false;
values: string[] = [];
static $inject: string[] = ["$http", "$window"];
constructor(private $http: ng.IHttpService, private $window: ng.IWindowService) {
this.getValues();
}
private getValues(): void {
this.$http.get("/api/sample")
.then((response: ng.IHttpPromiseCallbackArg<string[]>) => {
this.isVisibleErrorMessage = false;
this.values = response.data;
})
.catch(((reason: ng.IHttpPromiseCallbackArg<string[]>) => {
this.isVisibleErrorMessage = true;
this.errorMessage = reason.statusText;
return this.values;
}));
}
}
angular.module("app").controller("MyAppController", MyAppController);
}