In typescript I defined:
class SubjectService implements ISubjectService {
subject: any;
subjectId: number = 0;
subjects = {
"1": { "id": 1, "name": "Java" },
"100": { "id": 100, "name": "Test" }
};
static $inject = [
"$http",
"appConstant",
];
constructor(
public $http: ng.IHttpService,
public ac: IAppConstant
) {
}
}
I then in my constructor have this code:
class SubjectController {
static $inject = [
"$scope",
"subjectService"
];
constructor(
public $scope,
public su: ISubjectService
) {
$scope.su = su;
$scope.rowClicked = (subject, $index) => {
var self = this;
if (subject.current && subject.current == true) {
return;
}
su.subjects.forEach(function (subject) {
subject.current = false;
});
su.subject = subject;
su.subject.current = true;
}
}
}
But when this runs I am getting a message saying:
TypeError: su.subjects.forEach is not a function at Scope.SubjectController.$scope.rowClicked (http://localhost:1810/app/controllers/SubjectController.js:12:25)
Does anyone have any idea what might be wrong. I used similar code in other places but here it fails each time.