0

I have two angular with typescript projects, and I want one module (namespace in fact) to be available for both.

In project one, I have a module with a controller and a service. I want this functionality available in my second project, without copying the code.

Is it as simple as exporting the module and injecting it as a dependency on my new project?

I have tried this solution, but I have not succeeded. This is my code:

/// <reference path="../../typings/index.d.ts"/>

namespace Controllers {
"use strict";
    export class ExampleCtrl {

       public static $inject: Array<string> = [];

       private attrs;

       constructor() {
       // Stuff here
       }

       // Public and private methods, here
   }
angular.module("app.exampleCtrl").controller("ExampleCtrl", Controllers.ExampleCtrl);
}

How can I access this controller in my second project? I try this:

import {ExampleCtrl} from "../../directory/ExampleCtrl";

But TS linter shows an error that the module is not found.

1 Answer 1

1

Yes, it is that easy. You just need to call your module and its components (controllers, services, etc...) and inject them as a dependency in your new project.

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.