I am fairly new to TypeScript and AngularJS and I am struggling to find the correct answer for my issue. Below is the relevant code snippet:
export class SidenavController {
static $inject = ['$scope', '$mdSidenav'];
constructor(private $scope: any,private $mdSidenav: any) {
}
toggleSidenav(name: string) {
this.$mdSidenav(name).toggle();
}
loadHelpInfo() {
this.helpService.loadAll()
.then(function(help) {
this.$scope.helpInfo = [].concat(help);
this.$scope.selected = this.$scope.helpInfo[0];
})
}
selectHelpInfo(help) {
this.$scope.selected = angular.isNumber(help) ? this.$scope.helpInfo[help] : help;
this.$scope.toggleSidenav('left');
}
}
app.service('helpService', ['$q', function($q) {
var helpInfo = [{
name: 'Introduction',
content: '1 '
}, {
name: 'Glossary',
content: '2'
}, {
name: 'Log In',
content: '3'
}, {
name: 'Home Page',
content: '4'
}];
return {
loadAll: function() {
return $q.when(helpInfo);
}
};
}]);
While working on the above code, I encountered an error message: app/components/sidenav/sidenav-controller.ts(10,10): error TS2339: Property 'helpService' does not exist on type 'SidenavController'. I'm unsure on how to properly utilize services in TypeScript. If needed, I have also created a CodePen version of the Angular application:
http://codepen.io/snehav27/pen/JdNvBV
Essentially, I am attempting to convert the given code snippet into TypeScript version.