0

Angular has ng shortening for directives in markup, but how can I use that in js code. I mean when I write angular.isArray I'd prefer to write ng.isArray (as we do with jQuery ($), or Underscore (_)). Is it possible?

2 Answers 2

3

You can define var ng = angular; as a global variable, like JB Nizet suggested.

If you fear a conflict and prefer not to put anything in the global scope, you can wrap your code inside a Self-Executing Anonymous Function (closure) like this:

(function (ng) {
    // declare a module
    var myAppModule = ng.module('myApp', []);

    // configure myAppModule.
    // ...

})(angular);
Sign up to request clarification or add additional context in comments.

Comments

3

Define the following global variable:

var ng = angular;

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.