-
-
Save andreasderuiter/12711103380d6e0a5c69 to your computer and use it in GitHub Desktop.
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); | |
} |
I think this should actually be:
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;
//} <-- NB: Extra closing curly brace removed
return this.values;
}));
}
}
angular.module("app").controller("MyAppController", MyAppController);
}
Also, as crocodile says, it's a .TS file and not .CS
Thanks for the fix rachelppierson.
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);
}
This is a typescript file and not cs