0

New to TypeScript and trying to convert from js to ts (using angular 1.x). Here's a controller. Having issues converting to ts. "module" is a custom data element on the ui-router state provider.

(function(module) {
    "use strict";
    module.controller("aboutController", ["$state", function($state) {
            var vm = this;
            // todo: pass the module to the service to get the content for the about page from the db
            // $state.current.data.module
            vm.content = $state.current.data.module;
        }
    ]);
} (angular.module("app.ui")));

My latest attempt using ts:

module myApp.ui {
    "use strict";
    class AboutController {
        constructor(private $state: ng.ui.IStateProvider) {
            this.content = $state.current.data.module;
        }
    }
    angular.module("app.ui").controller("aboutController", AboutController);
}
5
  • And what is it that doesn't work? Commented Oct 13, 2015 at 18:05
  • Found my first problem. Was using IStateProvider instead of IStateService. Commented Oct 13, 2015 at 18:08
  • For the 'content' error, do I need to explicitly declare a class member? Is this required in TypeScript, unlike js? Commented Oct 13, 2015 at 18:15
  • 1
    @Ed.S. yes, just add the line content: any above your constructor (or below) Commented Oct 13, 2015 at 18:17
  • @EdSinek Do not include solution to question please (post a separate answer instead). Commented Dec 28, 2024 at 21:13

1 Answer 1

2

Property 'content' does not exist on type 'AboutController'

You need to declare all class properties in TypeScript:

class AboutController {
    content: any; // property declaration
    constructor(private $state: ng.ui.IStateProvider) {
        this.content = $state.current.data.module;
    }
}

Property 'current' does not exist on type 'IStateProvide`

Use IStateService. Note : these are generally services that you inject anyways and the suffix is consistent.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.