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?
问问题
83 次
2 回答
3
您可以定义var ng = angular;
为全局变量,就像 JB Nizet 建议的那样。
如果您担心冲突并且不想在全局范围内放置任何内容,则可以将代码包装在自执行匿名函数(闭包)中,如下所示:
(function (ng) {
// declare a module
var myAppModule = ng.module('myApp', []);
// configure myAppModule.
// ...
})(angular);
于 2013-07-28T17:22:26.820 回答
3
定义以下全局变量:
var ng = angular;
于 2013-07-28T17:01:17.230 回答