0

I'm using Typescript and AngularJs (1.6). When I need to declare a variable with an angular's type, I often hesitating between the two following syntaxes:

constructor(private $sce: ng.ISCEService) {}

and

import { ISCEService } from 'angular';

constructor(private $sce: ISCEService) {}

I assume these two pieces of code are doing the exact same things, but I'm not 200% sure.

My favourite is the first one as it does not require an import, but maybe I'm missing something. I'm curious, do you have some advise / opinion / best practice?

1 Answer 1

1

I assume these two pieces of code are doing the exact same things, but I'm not 200% sure.

They are saying the same thing. Difference depends on how your project is setup

  • If you are using angular globally e.g. using a script tag then use ng.
  • If you are using modules e.g. with webpack use imports import { ISCEService } from 'angular';
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you basarat. Interesting. Does it mean that if I plan to use webpack in the future, the import syntax is the way to go? Even with the help of angular typings?
You should use webpack today to keep sanity 🌹

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.