forked from rstropek/Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangularForm.ts
More file actions
69 lines (61 loc) · 1.84 KB
/
Copy pathangularForm.ts
File metadata and controls
69 lines (61 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class Person {
public firstName: string = "Max";
public lastName: string = "Muster";
public shortBio: string = "I am a funny guy!";
public firstJob: boolean = false;
public driverLicense: string = "None";
public sex: string = "male";
public languages: Language[] = [
{ language: "en", knowledge: "fluent" },
{ language: "de", knowledge: "native" }
];
}
class Language {
public language: string;
public knowledge: string;
}
class Application {
public person: Person;
constructor() {
this.person = new Person();
}
}
interface ISexOptions {
code: string;
description: string;
}
interface IBootstrapValidationClasses {
"has-success": boolean;
"has-error": boolean;
}
interface IApplicationScope extends ng.IScope {
application: Application;
sexOptions: ISexOptions[];
getCssClasses: (modelController: ng.INgModelController) => IBootstrapValidationClasses;
canSave: (modelController: ng.INgModelController) => boolean;
removeLanguage: (index: number) => void;
applicationForm: ng.INgModelController;
}
class ApplicationController {
constructor($scope: IApplicationScope) {
$scope.application = new Application();
$scope.sexOptions = [
{ code: "male", description: "Male" },
{ code: "female", description: "Female" }
];
$scope.getCssClasses = (ngModelController) => {
return {
"has-success": ngModelController.$dirty && ngModelController.$valid,
"has-error": ngModelController.$dirty && ngModelController.$invalid,
};
};
$scope.canSave = (ngModelController) => ngModelController.$dirty && ngModelController.$valid;
$scope.removeLanguage = (index) => {
$scope.application.person.languages.splice(index, 1);
$scope.applicationForm.$dirty = true;
};
}
}
angular.module("applicationApp", [])
.controller("applicationForm", ['$scope', ApplicationController]);