angular-ui-router.d.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Type definitions for Angular JS 1.1.5+ (ui.router module)
  2. // Project: https://github.com/angular-ui/ui-router
  3. // Definitions by: Michel Salib <https://github.com/michelsalib>
  4. // Definitions: https://github.com/borisyankov/DefinitelyTyped
  5. declare module ng.ui {
  6. interface IState {
  7. name?: string;
  8. template?: string;
  9. templateUrl?: any; // string || () => string
  10. templateProvider?: any; // () => string || IPromise<string>
  11. controller?: any;
  12. controllerAs?: string;
  13. controllerProvider?: any;
  14. resolve?: {};
  15. url?: string;
  16. params?: any;
  17. views?: {};
  18. abstract?: boolean;
  19. onEnter?: (...args: any[]) => void;
  20. onExit?: (...args: any[]) => void;
  21. data?: any;
  22. reloadOnSearch?: boolean;
  23. }
  24. interface ITypedState<T> extends IState {
  25. data?: T;
  26. }
  27. interface IStateProvider extends IServiceProvider {
  28. state(name: string, config: IState): IStateProvider;
  29. state(config: IState): IStateProvider;
  30. decorator(name?: string, decorator?: (state: IState, parent: Function) => any): any;
  31. }
  32. interface IUrlMatcher {
  33. concat(pattern: string): IUrlMatcher;
  34. exec(path: string, searchParams: {}): {};
  35. parameters(): string[];
  36. format(values: {}): string;
  37. }
  38. interface IUrlMatcherFactory {
  39. compile(pattern: string): IUrlMatcher;
  40. isMatcher(o: any): boolean;
  41. }
  42. interface IUrlRouterProvider extends IServiceProvider {
  43. when(whenPath: RegExp, handler: Function): IUrlRouterProvider;
  44. when(whenPath: RegExp, handler: any[]): IUrlRouterProvider;
  45. when(whenPath: RegExp, toPath: string): IUrlRouterProvider;
  46. when(whenPath: IUrlMatcher, hanlder: Function): IUrlRouterProvider;
  47. when(whenPath: IUrlMatcher, handler: any[]): IUrlRouterProvider;
  48. when(whenPath: IUrlMatcher, toPath: string): IUrlRouterProvider;
  49. when(whenPath: string, handler: Function): IUrlRouterProvider;
  50. when(whenPath: string, handler: any[]): IUrlRouterProvider;
  51. when(whenPath: string, toPath: string): IUrlRouterProvider;
  52. otherwise(handler: Function): IUrlRouterProvider;
  53. otherwise(handler: any[]): IUrlRouterProvider;
  54. otherwise(path: string): IUrlRouterProvider;
  55. rule(handler: Function): IUrlRouterProvider;
  56. rule(handler: any[]): IUrlRouterProvider;
  57. }
  58. interface IStateOptions {
  59. location?: any;
  60. inherit?: boolean;
  61. relative?: IState;
  62. notify?: boolean;
  63. reload?: boolean;
  64. }
  65. interface IHrefOptions {
  66. lossy?: boolean;
  67. inherit?: boolean;
  68. relative?: IState;
  69. absolute?: boolean;
  70. }
  71. interface IStateService {
  72. go(to: string, params?: {}, options?: IStateOptions): IPromise<any>;
  73. transitionTo(state: string, params?: {}, updateLocation?: boolean): void;
  74. transitionTo(state: string, params?: {}, options?: IStateOptions): void;
  75. includes(state: string, params?: {}): boolean;
  76. is(state:string, params?: {}): boolean;
  77. is(state: IState, params?: {}): boolean;
  78. href(state: IState, params?: {}, options?: IHrefOptions): string;
  79. href(state: string, params?: {}, options?: IHrefOptions): string;
  80. get(state: string): IState;
  81. get(): IState[];
  82. current: IState;
  83. params: any;
  84. reload(): void;
  85. }
  86. interface IStateParamsService {
  87. [key: string]: any;
  88. }
  89. interface IStateParams {
  90. [key: string]: any;
  91. }
  92. interface IUrlRouterService {
  93. /*
  94. * Triggers an update; the same update that happens when the address bar
  95. * url changes, aka $locationChangeSuccess.
  96. *
  97. * This method is useful when you need to use preventDefault() on the
  98. * $locationChangeSuccess event, perform some custom logic (route protection,
  99. * auth, config, redirection, etc) and then finally proceed with the transition
  100. * by calling $urlRouter.sync().
  101. *
  102. */
  103. sync(): void;
  104. }
  105. interface IUiViewScrollProvider {
  106. /*
  107. * Reverts back to using the core $anchorScroll service for scrolling
  108. * based on the url anchor.
  109. */
  110. useAnchorScroll(): void;
  111. }
  112. }