@types/angular
Version:
TypeScript definitions for angular
1,055 lines (949 loc) • 118 kB
TypeScript
/// <reference path="jqlite.d.ts" />
declare var angular: angular.IAngularStatic;
// Support for painless dependency injection
declare global {
interface Function {
$inject?: readonly string[] | undefined;
}
}
export as namespace angular;
export as namespace ng;
// Support AMD require
export = angular;
import ng = angular;
///////////////////////////////////////////////////////////////////////////////
// ng module (angular.js)
///////////////////////////////////////////////////////////////////////////////
declare namespace angular {
type Injectable<T extends Function> = T | Array<string | T>;
// not directly implemented, but ensures that constructed class implements $get
interface IServiceProviderClass {
new(...args: any[]): IServiceProvider;
}
interface IServiceProviderFactory {
(...args: any[]): IServiceProvider;
}
// All service providers extend this interface
interface IServiceProvider {
$get: any;
}
interface IAngularBootstrapConfig {
strictDi?: boolean | undefined;
}
///////////////////////////////////////////////////////////////////////////
// AngularStatic
// see http://docs.angularjs.org/api
///////////////////////////////////////////////////////////////////////////
interface IAngularStatic {
bind(context: any, fn: Function, ...args: any[]): Function;
/**
* Use this function to manually start up angular application.
*
* @param element DOM element which is the root of angular application.
* @param modules An array of modules to load into the application.
* Each item in the array should be the name of a predefined module or a (DI annotated)
* function that will be invoked by the injector as a config block.
* @param config an object for defining configuration options for the application. The following keys are supported:
* - `strictDi`: disable automatic function annotation for the application. This is meant to assist in finding bugs which break minified code.
*/
bootstrap(
element: string | Element | JQuery | Document,
modules?: Array<string | Function | any[]>,
config?: IAngularBootstrapConfig,
): auto.IInjectorService;
/**
* Creates a deep copy of source, which should be an object or an array.
*
* - If no destination is supplied, a copy of the object or array is created.
* - If a destination is provided, all of its elements (for array) or properties (for objects) are deleted and then all elements/properties from the source are copied to it.
* - If source is not an object or array (inc. null and undefined), source is returned.
* - If source is identical to 'destination' an exception will be thrown.
*
* @param source The source that will be used to make a copy. Can be any type, including primitives, null, and undefined.
* @param destination Destination into which the source is copied. If provided, must be of the same type as source.
*/
copy<T>(source: T, destination?: T): T;
/**
* Wraps a raw DOM element or HTML string as a jQuery element.
*
* If jQuery is available, angular.element is an alias for the jQuery function. If jQuery is not available, angular.element delegates to Angular's built-in subset of jQuery, called "jQuery lite" or "jqLite."
*/
element: JQueryStatic;
/**
* Configure several aspects of error handling in AngularJS if used as a setter
* or return the current configuration if used as a getter
*/
errorHandlingConfig(): IErrorHandlingConfig;
errorHandlingConfig(config: IErrorHandlingConfig): void;
equals(value1: any, value2: any): boolean;
extend(destination: any, ...sources: any[]): any;
/**
* Invokes the iterator function once for each item in obj collection, which can be either an object or an array. The iterator function is invoked with iterator(value, key), where value is the value of an object property or an array element and key is the object property key or array element index. Specifying a context for the function is optional.
*
* It is worth noting that .forEach does not iterate over inherited properties because it filters using the hasOwnProperty method.
*
* @param obj Object to iterate over.
* @param iterator Iterator function.
* @param context Object to become context (this) for the iterator function.
*/
forEach<T, U extends ArrayLike<T> = T[]>(
obj: U,
iterator: (value: U[number], key: number, obj: U) => void,
context?: any,
): U;
/**
* Invokes the iterator function once for each item in obj collection, which can be either an object or an array. The iterator function is invoked with iterator(value, key), where value is the value of an object property or an array element and key is the object property key or array element index. Specifying a context for the function is optional.
*
* It is worth noting that .forEach does not iterate over inherited properties because it filters using the hasOwnProperty method.
*
* @param obj Object to iterate over.
* @param iterator Iterator function.
* @param context Object to become context (this) for the iterator function.
*/
forEach<T>(
obj: { [index: string]: T },
iterator: (value: T, key: string, obj: { [index: string]: T }) => void,
context?: any,
): { [index: string]: T };
/**
* Invokes the iterator function once for each item in obj collection, which can be either an object or an array. The iterator function is invoked with iterator(value, key), where value is the value of an object property or an array element and key is the object property key or array element index. Specifying a context for the function is optional.
*
* It is worth noting that .forEach does not iterate over inherited properties because it filters using the hasOwnProperty method.
*
* @param obj Object to iterate over.
* @param iterator Iterator function.
* @param context Object to become context (this) for the iterator function.
*/
forEach(obj: any, iterator: (value: any, key: any, obj: any) => void, context?: any): any;
fromJson(json: string): any;
identity<T>(arg?: T): T;
injector(modules?: any[], strictDi?: boolean): auto.IInjectorService;
isArray(value: any): value is any[];
isDate(value: any): value is Date;
isDefined(value: any): boolean;
isElement(value: any): boolean;
isFunction(value: any): value is Function;
isNumber(value: any): value is number;
isObject(value: any): value is Object;
isObject<T>(value: any): value is T;
isString(value: any): value is string;
isUndefined(value: any): boolean;
/**
* Deeply extends the destination object dst by copying own enumerable properties from the src object(s) to dst. You can specify multiple src objects. If you want to preserve original objects, you can do so by passing an empty object as the target: var object = angular.merge({}, object1, object2).
*
* Unlike extend(), merge() recursively descends into object properties of source objects, performing a deep copy.
*
* @param dst Destination object.
* @param src Source object(s).
*/
merge(dst: any, ...src: any[]): any;
/**
* The angular.module is a global place for creating, registering and retrieving Angular modules. All modules (angular core or 3rd party) that should be available to an application must be registered using this mechanism.
*
* When passed two or more arguments, a new module is created. If passed only one argument, an existing module (the name passed as the first argument to module) is retrieved.
*
* @param name The name of the module to create or retrieve.
* @param requires The names of modules this module depends on. If specified then new module is being created. If unspecified then the module is being retrieved for further configuration.
* @param configFn Optional configuration function for the module.
*/
module(
name: string,
requires?: string[],
configFn?: Injectable<Function>,
): IModule;
noop(...args: any[]): void;
reloadWithDebugInfo(): void;
toJson(obj: any, pretty?: boolean | number): string;
version: {
full: string;
major: number;
minor: number;
dot: number;
codeName: string;
};
/**
* If window.name contains prefix NG_DEFER_BOOTSTRAP! when angular.bootstrap is called, the bootstrap process will be paused until angular.resumeBootstrap() is called.
* @param extraModules An optional array of modules that should be added to the original list of modules that the app was about to be bootstrapped with.
*/
resumeBootstrap?(extraModules?: string[]): ng.auto.IInjectorService;
/**
* Restores the pre-1.8 behavior of jqLite that turns XHTML-like strings like
* `<div /><span />` to `<div></div><span></span>` instead of `<div><span></span></div>`.
* The new behavior is a security fix so if you use this method, please try to adjust
* to the change & remove the call as soon as possible.
* Note that this only patches jqLite. If you use jQuery 3.5.0 or newer, please read
* [jQuery 3.5 upgrade guide](https://jquery.com/upgrade-guide/3.5/) for more details
* about the workarounds.
*/
UNSAFE_restoreLegacyJqLiteXHTMLReplacement(): void;
}
///////////////////////////////////////////////////////////////////////////
// Module
// see http://docs.angularjs.org/api/angular.Module
///////////////////////////////////////////////////////////////////////////
interface IModule {
/**
* Use this method to register a component.
*
* @param name The name of the component.
* @param options A definition object passed into the component.
*/
component(name: string, options: IComponentOptions): IModule;
/**
* Use this method to register a component.
*
* @param object Object map of components where the keys are the names and the values are the component definition objects
*/
component(object: { [componentName: string]: IComponentOptions }): IModule;
/**
* Use this method to register work which needs to be performed on module loading.
*
* @param configFn Execute this function on module load. Useful for service configuration.
*/
config(configFn: Function): IModule;
/**
* Use this method to register work which needs to be performed on module loading.
*
* @param inlineAnnotatedFunction Execute this function on module load. Useful for service configuration.
*/
config(inlineAnnotatedFunction: any[]): IModule;
config(object: Object): IModule;
/**
* Register a constant service, such as a string, a number, an array, an object or a function, with the $injector. Unlike value it can be injected into a module configuration function (see config) and it cannot be overridden by an Angular decorator.
*
* @param name The name of the constant.
* @param value The constant value.
*/
constant<T>(name: string, value: T): IModule;
constant(object: Object): IModule;
/**
* The $controller service is used by Angular to create new controllers.
*
* This provider allows controller registration via the register method.
*
* @param name Controller name, or an object map of controllers where the keys are the names and the values are the constructors.
* @param controllerConstructor Controller constructor fn (optionally decorated with DI annotations in the array notation).
*/
controller(name: string, controllerConstructor: Injectable<IControllerConstructor>): IModule;
controller(object: { [name: string]: Injectable<IControllerConstructor> }): IModule;
/**
* Register a new directive with the compiler.
*
* @param name Name of the directive in camel-case (i.e. ngBind which will match as ng-bind)
* @param directiveFactory An injectable directive factory function.
*/
directive<
TScope extends IScope = IScope,
TElement extends JQLite = JQLite,
TAttributes extends IAttributes = IAttributes,
TController extends IDirectiveController = IController,
>(
name: string,
directiveFactory: Injectable<IDirectiveFactory<TScope, TElement, TAttributes, TController>>,
): IModule;
directive<
TScope extends IScope = IScope,
TElement extends JQLite = JQLite,
TAttributes extends IAttributes = IAttributes,
TController extends IDirectiveController = IController,
>(
object: {
[directiveName: string]: Injectable<IDirectiveFactory<TScope, TElement, TAttributes, TController>>;
},
): IModule;
/**
* Register a service factory, which will be called to return the service instance. This is short for registering a service where its provider consists of only a $get property, which is the given service factory function. You should use $provide.factory(getFn) if you do not need to configure your service in a provider.
*
* @param name The name of the instance.
* @param $getFn The $getFn for the instance creation. Internally this is a short hand for $provide.provider(name, {$get: $getFn}).
*/
factory(name: string, $getFn: Injectable<Function>): IModule;
factory(object: { [name: string]: Injectable<Function> }): IModule;
filter(name: string, filterFactoryFunction: Injectable<FilterFactory>): IModule;
filter(object: { [name: string]: Injectable<FilterFactory> }): IModule;
provider(name: string, serviceProviderFactory: IServiceProviderFactory): IModule;
provider(name: string, serviceProviderConstructor: IServiceProviderClass): IModule;
provider(name: string, inlineAnnotatedConstructor: any[]): IModule;
provider(name: string, providerObject: IServiceProvider): IModule;
provider(object: Object): IModule;
/**
* Run blocks are the closest thing in Angular to the main method. A run block is the code which needs to run to kickstart the application. It is executed after all of the service have been configured and the injector has been created. Run blocks typically contain code which is hard to unit-test, and for this reason should be declared in isolated modules, so that they can be ignored in the unit-tests.
*/
run(initializationFunction: Injectable<Function>): IModule;
/**
* Register a service constructor, which will be invoked with new to create the service instance. This is short for registering a service where its provider's $get property is a factory function that returns an instance instantiated by the injector from the service constructor function.
*
* @param name The name of the instance.
* @param serviceConstructor An injectable class (constructor function) that will be instantiated.
*/
service(name: string, serviceConstructor: Injectable<Function>): IModule;
service(object: { [name: string]: Injectable<Function> }): IModule;
/**
* Register a value service with the $injector, such as a string, a number, an array, an object or a function. This is short for registering a service where its provider's $get property is a factory function that takes no arguments and returns the value service.
Value services are similar to constant services, except that they cannot be injected into a module configuration function (see config) but they can be overridden by an Angular decorator.
*
* @param name The name of the instance.
* @param value The value.
*/
value<T>(name: string, value: T): IModule;
value(object: Object): IModule;
/**
* Register a service decorator with the $injector. A service decorator intercepts the creation of a service, allowing it to override or modify the behaviour of the service. The object returned by the decorator may be the original service, or a new service object which replaces or wraps and delegates to the original service.
* @param name The name of the service to decorate
* @param decorator This function will be invoked when the service needs to be instantiated and should return the decorated service instance. The function is called using the injector.invoke method and is therefore fully injectable. Local injection arguments: $delegate - The original service instance, which can be monkey patched, configured, decorated or delegated to.
*/
decorator(name: string, decorator: Injectable<Function>): IModule;
// Properties
name: string;
requires: string[];
}
///////////////////////////////////////////////////////////////////////////
// Attributes
// see http://docs.angularjs.org/api/ng/type/$compile.directive.Attributes
///////////////////////////////////////////////////////////////////////////
interface IAttributes {
/**
* this is necessary to be able to access the scoped attributes. it's not very elegant
* because you have to use attrs['foo'] instead of attrs.foo but I don't know of a better way
* this should really be limited to return string but it creates this problem: http://stackoverflow.com/q/17201854/165656
*/
[name: string]: any;
/**
* Converts an attribute name (e.g. dash/colon/underscore-delimited string, optionally prefixed with x- or data-) to its normalized, camelCase form.
*
* Also there is special case for Moz prefix starting with upper case letter.
*
* For further information check out the guide on @see https://docs.angularjs.org/guide/directive#matching-directives
*/
$normalize(name: string): string;
/**
* Adds the CSS class value specified by the classVal parameter to the
* element. If animations are enabled then an animation will be triggered
* for the class addition.
*/
$addClass(classVal: string): void;
/**
* Removes the CSS class value specified by the classVal parameter from the
* element. If animations are enabled then an animation will be triggered for
* the class removal.
*/
$removeClass(classVal: string): void;
/**
* Adds and removes the appropriate CSS class values to the element based on the difference between
* the new and old CSS class values (specified as newClasses and oldClasses).
*/
$updateClass(newClasses: string, oldClasses: string): void;
/**
* Set DOM element attribute value.
*/
$set(key: string, value: any): void;
/**
* Observes an interpolated attribute.
* The observer function will be invoked once during the next $digest
* following compilation. The observer is then invoked whenever the
* interpolated value changes.
*/
$observe<T>(name: string, fn: (value?: T) => any): Function;
/**
* A map of DOM element attribute names to the normalized name. This is needed
* to do reverse lookup from normalized name back to actual name.
*/
$attr: Object;
}
/**
* form.FormController - type in module ng
* see https://docs.angularjs.org/api/ng/type/form.FormController
*/
interface IFormController {
/**
* Indexer which should return ng.INgModelController for most properties but cannot because of "All named properties must be assignable to string indexer type" constraint - see https://github.com/Microsoft/TypeScript/issues/272
*/
[name: string]: any;
$pristine: boolean;
$dirty: boolean;
$valid: boolean;
$invalid: boolean;
$submitted: boolean;
$error: { [validationErrorKey: string]: Array<INgModelController | IFormController> };
$name?: string | undefined;
$pending?: { [validationErrorKey: string]: Array<INgModelController | IFormController> } | undefined;
$addControl(control: INgModelController | IFormController): void;
$getControls(): ReadonlyArray<INgModelController | IFormController>;
$removeControl(control: INgModelController | IFormController): void;
$setValidity(validationErrorKey: string, isValid: boolean, control: INgModelController | IFormController): void;
$setDirty(): void;
$setPristine(): void;
$commitViewValue(): void;
$rollbackViewValue(): void;
$setSubmitted(): void;
$setUntouched(): void;
}
///////////////////////////////////////////////////////////////////////////
// NgModelController
// see http://docs.angularjs.org/api/ng/type/ngModel.NgModelController
///////////////////////////////////////////////////////////////////////////
interface INgModelController {
$render(): void;
$setValidity(validationErrorKey: string, isValid: boolean): void;
// Documentation states viewValue and modelValue to be a string but other
// types do work and it's common to use them.
$setViewValue(value: any, trigger?: string): void;
$setPristine(): void;
$setDirty(): void;
$validate(): void;
$setTouched(): void;
$setUntouched(): void;
$rollbackViewValue(): void;
$commitViewValue(): void;
$processModelValue(): void;
$isEmpty(value: any): boolean;
$overrideModelOptions(options: INgModelOptions): void;
$viewValue: any;
$modelValue: any;
$parsers: IModelParser[];
$formatters: IModelFormatter[];
$viewChangeListeners: IModelViewChangeListener[];
$error: { [validationErrorKey: string]: boolean };
$name?: string | undefined;
$touched: boolean;
$untouched: boolean;
$validators: IModelValidators;
$asyncValidators: IAsyncModelValidators;
$pending?: { [validationErrorKey: string]: boolean } | undefined;
$pristine: boolean;
$dirty: boolean;
$valid: boolean;
$invalid: boolean;
}
// Allows tuning how model updates are done.
// https://docs.angularjs.org/api/ng/directive/ngModelOptions
interface INgModelOptions {
updateOn?: string | undefined;
debounce?: number | { [key: string]: number } | undefined;
allowInvalid?: boolean | undefined;
getterSetter?: boolean | undefined;
timezone?: string | undefined;
/**
* Defines if the time and datetime-local types should show seconds and milliseconds.
* The option follows the format string of date filter.
* By default, the options is undefined which is equal to 'ss.sss' (seconds and milliseconds)
*/
timeSecondsFormat?: string | undefined;
/**
* Defines if the time and datetime-local types should strip the seconds and milliseconds
* from the formatted value if they are zero. This option is applied after `timeSecondsFormat`
*/
timeStripZeroSeconds?: boolean | undefined;
}
interface IModelValidators {
/**
* viewValue is any because it can be an object that is called in the view like $viewValue.name:$viewValue.subName
*/
[index: string]: (modelValue: any, viewValue: any) => boolean;
}
interface IAsyncModelValidators {
[index: string]: (modelValue: any, viewValue: any) => IPromise<any>;
}
interface IErrorHandlingConfig {
/**
* The max depth for stringifying objects.
* Setting to a non-positive or non-numeric value, removes the max depth limit
* @default 5
*/
objectMaxDepth?: number | undefined;
/**
* Specifies whether the generated error url will contain the parameters of the thrown error.
* Disabling the parameters can be useful if the generated error url is very long.
* @default true;
*/
urlErrorParamsEnabled?: boolean | undefined;
}
interface IModelParser {
(value: any): any;
}
interface IModelFormatter {
(value: any): any;
}
interface IModelViewChangeListener {
(): void;
}
/**
* $rootScope - $rootScopeProvider - service in module ng
* see https://docs.angularjs.org/api/ng/type/$rootScope.Scope and https://docs.angularjs.org/api/ng/service/$rootScope
*/
interface IRootScopeService {
$apply(): any;
$apply(exp: string): any;
$apply(exp: (scope: IScope) => any): any;
$applyAsync(): any;
$applyAsync(exp: string): any;
$applyAsync(exp: (scope: IScope) => any): any;
/**
* Dispatches an event name downwards to all child scopes (and their children) notifying the registered $rootScope.Scope listeners.
*
* The event life cycle starts at the scope on which $broadcast was called. All listeners listening for name event on this scope get notified. Afterwards, the event propagates to all direct and indirect scopes of the current scope and calls all registered listeners along the way. The event cannot be canceled.
*
* Any exception emitted from the listeners will be passed onto the $exceptionHandler service.
*
* @param name Event name to broadcast.
* @param args Optional one or more arguments which will be passed onto the event listeners.
*/
$broadcast(name: string, ...args: any[]): IAngularEvent;
$destroy(): void;
$digest(): void;
/**
* Suspend watchers of this scope subtree so that they will not be invoked during digest.
*
* This can be used to optimize your application when you know that running those watchers
* is redundant.
*
* **Warning**
*
* Suspending scopes from the digest cycle can have unwanted and difficult to debug results.
* Only use this approach if you are confident that you know what you are doing and have
* ample tests to ensure that bindings get updated as you expect.
*
* Some of the things to consider are:
*
* * Any external event on a directive/component will not trigger a digest while the hosting
* scope is suspended - even if the event handler calls `$apply()` or `$rootScope.$digest()`.
* * Transcluded content exists on a scope that inherits from outside a directive but exists
* as a child of the directive's containing scope. If the containing scope is suspended the
* transcluded scope will also be suspended, even if the scope from which the transcluded
* scope inherits is not suspended.
* * Multiple directives trying to manage the suspended status of a scope can confuse each other:
* * A call to `$suspend()` on an already suspended scope is a no-op.
* * A call to `$resume()` on a non-suspended scope is a no-op.
* * If two directives suspend a scope, then one of them resumes the scope, the scope will no
* longer be suspended. This could result in the other directive believing a scope to be
* suspended when it is not.
* * If a parent scope is suspended then all its descendants will be also excluded from future
* digests whether or not they have been suspended themselves. Note that this also applies to
* isolate child scopes.
* * Calling `$digest()` directly on a descendant of a suspended scope will still run the watchers
* for that scope and its descendants. When digesting we only check whether the current scope is
* locally suspended, rather than checking whether it has a suspended ancestor.
* * Calling `$resume()` on a scope that has a suspended ancestor will not cause the scope to be
* included in future digests until all its ancestors have been resumed.
* * Resolved promises, e.g. from explicit `$q` deferreds and `$http` calls, trigger `$apply()`
* against the `$rootScope` and so will still trigger a global digest even if the promise was
* initiated by a component that lives on a suspended scope.
*/
$suspend(): void;
/**
* Call this method to determine if this scope has been explicitly suspended. It will not
* tell you whether an ancestor has been suspended.
* To determine if this scope will be excluded from a digest triggered at the $rootScope,
* for example, you must check all its ancestors:
*
* ```
* function isExcludedFromDigest(scope) {
* while(scope) {
* if (scope.$isSuspended()) return true;
* scope = scope.$parent;
* }
* return false;
* ```
*
* Be aware that a scope may not be included in digests if it has a suspended ancestor,
* even if `$isSuspended()` returns false.
*
* @returns true if the current scope has been suspended.
*/
$isSuspended(): boolean;
/**
* Resume watchers of this scope subtree in case it was suspended.
*
* See {$rootScope.Scope#$suspend} for information about the dangers of using this approach.
*/
$resume(): void;
/**
* Dispatches an event name upwards through the scope hierarchy notifying the registered $rootScope.Scope listeners.
*
* The event life cycle starts at the scope on which $emit was called. All listeners listening for name event on this scope get notified. Afterwards, the event traverses upwards toward the root scope and calls all registered listeners along the way. The event will stop propagating if one of the listeners cancels it.
*
* Any exception emitted from the listeners will be passed onto the $exceptionHandler service.
*
* @param name Event name to emit.
* @param args Optional one or more arguments which will be passed onto the event listeners.
*/
$emit(name: string, ...args: any[]): IAngularEvent;
$eval(): any;
$eval(expression: string, locals?: Object): any;
$eval(expression: (scope: IScope) => any, locals?: Object): any;
$evalAsync(): void;
$evalAsync(expression: string, locals?: Object): void;
$evalAsync(expression: (scope: IScope) => void, locals?: Object): void;
// Defaults to false by the implementation checking strategy
$new(isolate?: boolean, parent?: IScope): IScope;
/**
* Listens on events of a given type. See $emit for discussion of event life cycle.
*
* The event listener function format is: function(event, args...).
*
* @param name Event name to listen on.
* @param listener Function to call when the event is emitted.
*/
$on(name: string, listener: (event: IAngularEvent, ...args: any[]) => any): () => void;
$watch(watchExpression: string, listener?: string, objectEquality?: boolean): () => void;
$watch<T>(
watchExpression: string,
listener?: (newValue: T, oldValue: T, scope: IScope) => any,
objectEquality?: boolean,
): () => void;
$watch(watchExpression: (scope: IScope) => any, listener?: string, objectEquality?: boolean): () => void;
$watch<T>(
watchExpression: (scope: IScope) => T,
listener?: (newValue: T, oldValue: T, scope: IScope) => any,
objectEquality?: boolean,
): () => void;
$watchCollection<T>(
watchExpression: string,
listener: (newValue: T, oldValue: T, scope: IScope) => any,
): () => void;
$watchCollection<T>(
watchExpression: (scope: IScope) => T,
listener: (newValue: T, oldValue: T, scope: IScope) => any,
): () => void;
$watchGroup(
watchExpressions: any[],
listener: (newValue: any, oldValue: any, scope: IScope) => any,
): () => void;
$watchGroup(
watchExpressions: Array<{ (scope: IScope): any }>,
listener: (newValue: any, oldValue: any, scope: IScope) => any,
): () => void;
$parent: IScope;
$root: IRootScopeService;
$id: number;
// Hidden members
$$isolateBindings: any;
$$phase: any;
}
interface IScope extends IRootScopeService {}
/**
* $scope for ngRepeat directive.
* see https://docs.angularjs.org/api/ng/directive/ngRepeat
*/
interface IRepeatScope extends IScope {
/**
* iterator offset of the repeated element (0..length-1).
*/
$index: number;
/**
* true if the repeated element is first in the iterator.
*/
$first: boolean;
/**
* true if the repeated element is between the first and last in the iterator.
*/
$middle: boolean;
/**
* true if the repeated element is last in the iterator.
*/
$last: boolean;
/**
* true if the iterator position $index is even (otherwise false).
*/
$even: boolean;
/**
* true if the iterator position $index is odd (otherwise false).
*/
$odd: boolean;
}
interface IAngularEvent {
/**
* the scope on which the event was $emit-ed or $broadcast-ed.
*/
targetScope: IScope;
/**
* the scope that is currently handling the event. Once the event propagates through the scope hierarchy, this property is set to null.
*/
currentScope: IScope;
/**
* name of the event.
*/
name: string;
/**
* calling stopPropagation function will cancel further event propagation (available only for events that were $emit-ed).
*/
stopPropagation?(): void;
/**
* calling preventDefault sets defaultPrevented flag to true.
*/
preventDefault(): void;
/**
* true if preventDefault was called.
*/
defaultPrevented: boolean;
}
///////////////////////////////////////////////////////////////////////////
// WindowService
// see http://docs.angularjs.org/api/ng/service/$window
///////////////////////////////////////////////////////////////////////////
interface IWindowService extends Window {
[key: string]: any;
}
///////////////////////////////////////////////////////////////////////////
// TimeoutService
// see http://docs.angularjs.org/api/ng/service/$timeout
///////////////////////////////////////////////////////////////////////////
interface ITimeoutService {
(delay?: number, invokeApply?: boolean): IPromise<void>;
<T>(
fn: (...args: any[]) => T | IPromise<T>,
delay?: number,
invokeApply?: boolean,
...args: any[]
): IPromise<T>;
cancel(promise?: IPromise<any>): boolean;
}
///////////////////////////////////////////////////////////////////////////
// IntervalService
// see http://docs.angularjs.org/api/ng/service/$interval
///////////////////////////////////////////////////////////////////////////
interface IIntervalService {
(func: Function, delay: number, count?: number, invokeApply?: boolean, ...args: any[]): IPromise<any>;
cancel(promise: IPromise<any>): boolean;
}
/**
* $filter - $filterProvider - service in module ng
*
* Filters are used for formatting data displayed to the user.
*
* see https://docs.angularjs.org/api/ng/service/$filter
*/
interface IFilterService {
(name: "filter"): IFilterFilter;
(name: "currency"): IFilterCurrency;
(name: "number"): IFilterNumber;
(name: "date"): IFilterDate;
(name: "json"): IFilterJson;
(name: "lowercase"): IFilterLowercase;
(name: "uppercase"): IFilterUppercase;
(name: "limitTo"): IFilterLimitTo;
(name: "orderBy"): IFilterOrderBy;
/**
* Usage:
* $filter(name);
*
* @param name Name of the filter function to retrieve
*/
<T>(name: string): T;
}
interface IFilterFilter {
<T>(
array: T[],
expression: string | IFilterFilterPatternObject | IFilterFilterPredicateFunc<T>,
comparator?: IFilterFilterComparatorFunc<T> | boolean,
): T[];
}
interface IFilterFilterPatternObject {
[name: string]: any;
}
interface IFilterFilterPredicateFunc<T> {
(value: T, index: number, array: T[]): boolean;
}
interface IFilterFilterComparatorFunc<T> {
(actual: T, expected: T): boolean;
}
interface IFilterOrderByItem {
value: any;
type: string;
index: any;
}
interface IFilterOrderByComparatorFunc {
(left: IFilterOrderByItem, right: IFilterOrderByItem): -1 | 0 | 1;
}
interface IFilterCurrency {
/**
* Formats a number as a currency (ie $1,234.56). When no currency symbol is provided, default symbol for current locale is used.
* @param amount Input to filter.
* @param symbol Currency symbol or identifier to be displayed.
* @param fractionSize Number of decimal places to round the amount to, defaults to default max fraction size for current locale
* @return Formatted number
*/
(amount: number, symbol?: string, fractionSize?: number): string;
}
interface IFilterNumber {
/**
* Formats a number as text.
* @param number Number to format.
* @param fractionSize Number of decimal places to round the number to. If this is not provided then the fraction size is computed from the current locale's number formatting pattern. In the case of the default locale, it will be 3.
* @return Number rounded to decimalPlaces and places a “,” after each third digit.
*/
(value: number | string, fractionSize?: number | string): string;
}
interface IFilterDate {
/**
* Formats date to a string based on the requested format.
*
* @param date Date to format either as Date object, milliseconds (string or number) or various ISO 8601 datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.sssZ and its shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ). If no timezone is specified in the string input, the time is considered to be in the local timezone.
* @param format Formatting rules (see Description). If not specified, mediumDate is used.
* @param timezone Timezone to be used for formatting. It understands UTC/GMT and the continental US time zone abbreviations, but for general use, use a time zone offset, for example, '+0430' (4 hours, 30 minutes east of the Greenwich meridian) If not specified, the timezone of the browser will be used.
* @return Formatted string or the input if input is not recognized as date/millis.
*/
(date: Date | number | string, format?: string, timezone?: string): string;
}
interface IFilterJson {
/**
* Allows you to convert a JavaScript object into JSON string.
* @param object Any JavaScript object (including arrays and primitive types) to filter.
* @param spacing The number of spaces to use per indentation, defaults to 2.
* @return JSON string.
*/
(object: any, spacing?: number): string;
}
interface IFilterLowercase {
/**
* Converts string to lowercase.
*/
(value: string): string;
}
interface IFilterUppercase {
/**
* Converts string to uppercase.
*/
(value: string): string;
}
interface IFilterLimitTo {
/**
* Creates a new array containing only a specified number of elements. The elements are taken from either the beginning or the end of the source array, string or number, as specified by the value and sign (positive or negative) of limit.
* @param input Source array to be limited.
* @param limit The length of the returned array. If the limit number is positive, limit number of items from the beginning of the source array/string are copied. If the number is negative, limit number of items from the end of the source array are copied. The limit will be trimmed if it exceeds array.length. If limit is undefined, the input will be returned unchanged.
* @param begin Index at which to begin limitation. As a negative index, begin indicates an offset from the end of input. Defaults to 0.
* @return A new sub-array of length limit or less if input array had less than limit elements.
*/
<T>(input: T[], limit: string | number, begin?: string | number): T[];
/**
* Creates a new string containing only a specified number of elements. The elements are taken from either the beginning or the end of the source string or number, as specified by the value and sign (positive or negative) of limit. If a number is used as input, it is converted to a string.
* @param input Source string or number to be limited.
* @param limit The length of the returned string. If the limit number is positive, limit number of items from the beginning of the source string are copied. If the number is negative, limit number of items from the end of the source string are copied. The limit will be trimmed if it exceeds input.length. If limit is undefined, the input will be returned unchanged.
* @param begin Index at which to begin limitation. As a negative index, begin indicates an offset from the end of input. Defaults to 0.
* @return A new substring of length limit or less if input had less than limit elements.
*/
(input: string | number, limit: string | number, begin?: string | number): string;
}
interface IFilterOrderBy {
/**
* Orders a specified array by the expression predicate. It is ordered alphabetically for strings and numerically for numbers. Note: if you notice numbers are not being sorted as expected, make sure they are actually being saved as numbers and not strings.
* @param array The array to sort.
* @param expression A predicate to be used by the comparator to determine the order of elements.
* @param reverse Reverse the order of the array.
* @param comparator Function used to determine the relative order of value pairs.
* @return An array containing the items from the specified collection, ordered by a comparator function based on the values computed using the expression predicate.
*/
<T>(
array: T[],
expression: string | ((value: T) => any) | Array<((value: T) => any) | string>,
reverse?: boolean,
comparator?: IFilterOrderByComparatorFunc,
): T[];
}
/**
* $filterProvider - $filter - provider in module ng
*
* Filters are just functions which transform input to an output. However filters need to be Dependency Injected. To achieve this a filter definition consists of a factory function which is annotated with dependencies and is responsible for creating a filter function.
*
* see https://docs.angularjs.org/api/ng/provider/$filterProvider
*/
interface IFilterProvider extends IServiceProvider {
/**
* register(name);
*
* @param name Name of the filter function, or an object map of filters where the keys are the filter names and the values are the filter factories. Note: Filter names must be valid angular Expressions identifiers, such as uppercase or orderBy. Names with special characters, such as hyphens and dots, are not allowed. If you wish to namespace your filters, then you can use capitalization (myappSubsectionFilterx) or underscores (myapp_subsection_filterx).
*/
register(name: string | {}): IServiceProvider;
}
///////////////////////////////////////////////////////////////////////////
// LocaleService
// see http://docs.angularjs.org/api/ng/service/$locale
///////////////////////////////////////////////////////////////////////////
interface ILocaleService {
id: string;
// These are not documented
// Check angular's i18n files for exemples
NUMBER_FORMATS: ILocaleNumberFormatDescriptor;
DATETIME_FORMATS: ILocaleDateTimeFormatDescriptor;
pluralCat(num: any): string;
}
interface ILocaleNumberFormatDescriptor {
DECIMAL_SEP: string;
GROUP_SEP: string;
PATTERNS: ILocaleNumberPatternDescriptor[];
CURRENCY_SYM: string;
}
interface ILocaleNumberPatternDescriptor {
minInt: number;
minFrac: number;
maxFrac: number;
posPre: string;
posSuf: string;
negPre: string;
negSuf: string;
gSize: number;
lgSize: number;
}
interface ILocaleDateTimeFormatDescriptor {
MONTH: string[];
SHORTMONTH: string[];
DAY: string[];
SHORTDAY: string[];
AMPMS: string[];
medium: string;
short: string;
fullDate: string;
longDate: string;
mediumDate: string;
shortDate: string;
mediumTime: string;
shortTime: string;
}
///////////////////////////////////////////////////////////////////////////
// LogService
// see http://docs.angularjs.org/api/ng/service/$log
// see http://docs.angularjs.org/api/ng/provider/$logProvider
///////////////////////////////////////////////////////////////////////////
interface ILogService {
debug: ILogCall;
error: ILogCall;
info: ILogCall;
log: ILogCall;
warn: ILogCall;
}
interface ILogProvider extends IServiceProvider {
debugEnabled(): boolean;
debugEnabled(enabled: boolean): ILogProvider;
}
// We define this as separate interface so we can reopen it later for
// the ngMock module.
interface ILogCall {
(...args: any[]): void;
}
///////////////////////////////////////////////////////////////////////////
// ParseService
// see http://docs.angularjs.org/api/ng/service/$parse
// see http://docs.angularjs.org/api/ng/provider/$parseProvider
///////////////////////////////////////////////////////////////////////////
interface IParseService {
(
expression: string,
interceptorFn?: (value: any, scope: IScope, locals: any) => any,
expensiveChecks?: boolean,
): ICompiledExpression;
}
interface IParseProvider {
logPromiseWarnings(): boolean;
logPromiseWarnings(value: boolean): IParseProvider;
unwrapPromises(): boolean;
unwrapPromises(value: boolean): IParseProvider;
/**
* Configure $parse service to add literal values that will be present as literal at expressions.
*
* @param literalName Token for the literal value. The literal name value must be a valid literal name.
* @param literalValue Value for this literal. All literal values must be primitives or `undefined`.
*/
addLiteral(literalName: string, literalValue: any): void;
/**
* Allows defining the set of characters that are allowed in Angular expressions. The function identifierStart will get called to know if a given character is a valid character to be the first character for an identifier. The function identifierContinue will get called to know if a given character is a valid character to be a follow-up identifier character. The functions identifierStart and identifierContinue will receive as arguments the single character to be identifier and the character code point. These arguments will be string and numeric. Keep in mind that the string parameter can be two characters long depending on the character representation. It is expected for the function to return true or false, whether that character is allowed or not.
* Since this function will be called extensivelly, keep the implementation of these functions fast, as th