當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript core.isFunction函數代碼示例

本文整理匯總了TypeScript中@uirouter/core.isFunction函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript isFunction函數的具體用法?TypeScript isFunction怎麽用?TypeScript isFunction使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了isFunction函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: when

  /**
   * Registers a handler for a given url matching.
   *
   * If the handler is a string, it is
   * treated as a redirect, and is interpolated according to the syntax of match
   * (i.e. like `String.replace()` for `RegExp`, or like a `UrlMatcher` pattern otherwise).
   *
   * If the handler is a function, it is injectable.
   * It gets invoked if `$location` matches.
   * You have the option of inject the match object as `$match`.
   *
   * The handler can return
   *
   * - **falsy** to indicate that the rule didn't match after all, then `$urlRouter`
   *   will continue trying to find another one that matches.
   * - **string** which is treated as a redirect and passed to `$location.url()`
   * - **void** or any **truthy** value tells `$urlRouter` that the url was handled.
   *
   * #### Example:
   * ```js
   * var app = angular.module('app', ['ui.router.router']);
   *
   * app.config(function ($urlRouterProvider) {
   *   $urlRouterProvider.when($state.url, function ($match, $stateParams) {
   *     if ($state.$current.navigable !== state ||
   *         !equalForKeys($match, $stateParams) {
   *      $state.transitionTo(state, $match, false);
   *     }
   *   });
   * });
   * ```
   *
   * @param what A pattern string to match, compiled as a [[UrlMatcher]].
   * @param handler The path (or function that returns a path) that you want to redirect your user to.
   * @param ruleCallback [optional] A callback that receives the `rule` registered with [[UrlMatcher.rule]]
   *
   * Note: the handler may also invoke arbitrary code, such as `$state.go()`
   */
  when(what: (RegExp|UrlMatcher|string), handler: string|IInjectable) {
    if (isArray(handler) || isFunction(handler)) {
      handler = UrlRouterProvider.injectableHandler(this._router, handler);
    }

    this._urlRouter.when(what, handler as any);
    return this;
  };
開發者ID:apetrosian,項目名稱:ui-router,代碼行數:46,代碼來源:urlRouterProvider.ts

示例2: when

  /**
   * Registers a handler for a given url matching.
   *
   * If the handler is a string, it is
   * treated as a redirect, and is interpolated according to the syntax of match
   * (i.e. like `String.replace()` for `RegExp`, or like a `UrlMatcher` pattern otherwise).
   *
   * If the handler is a function, it is injectable.
   * It gets invoked if `$location` matches.
   * You have the option of inject the match object as `$match`.
   *
   * The handler can return
   *
   * - **falsy** to indicate that the rule didn't match after all, then `$urlRouter`
   *   will continue trying to find another one that matches.
   * - **string** which is treated as a redirect and passed to `$location.url()`
   * - **void** or any **truthy** value tells `$urlRouter` that the url was handled.
   *
   * #### Example:
   * ```js
   * var app = angular.module('app', ['ui.router.router']);
   *
   * app.config(function ($urlRouterProvider) {
   *   $urlRouterProvider.when($state.url, function ($match, $stateParams) {
   *     if ($state.$current.navigable !== state ||
   *         !equalForKeys($match, $stateParams) {
   *      $state.transitionTo(state, $match, false);
   *     }
   *   });
   * });
   * ```
   *
   * @param what A pattern string to match, compiled as a [[UrlMatcher]].
   * @param handler The path (or function that returns a path) that you want to redirect your user to.
   * @param ruleCallback [optional] A callback that receives the `rule` registered with [[UrlMatcher.rule]]
   *
   * Note: the handler may also invoke arbitrary code, such as `$state.go()`
   */
  when(what: RegExp | UrlMatcher | string, handler: string | IInjectable) {
    if (isArray(handler) || isFunction(handler)) {
      handler = UrlRouterProvider.injectableHandler(this.router, handler);
    }

    this.router.urlService.rules.when(what, handler as any);
    return this;
  }
開發者ID:angular-ui,項目名稱:ui-router,代碼行數:46,代碼來源:urlRouterProvider.ts

示例3: rule

  /**
   * Registers a url handler function.
   *
   * Registers a low level url handler (a `rule`).
   * A rule detects specific URL patterns and returns a redirect, or performs some action.
   *
   * If a rule returns a string, the URL is replaced with the string, and all rules are fired again.
   *
   * #### Example:
   * ```js
   * var app = angular.module('app', ['ui.router.router']);
   *
   * app.config(function ($urlRouterProvider) {
   *   // Here's an example of how you might allow case insensitive urls
   *   $urlRouterProvider.rule(function ($injector, $location) {
   *     var path = $location.path(),
   *         normalized = path.toLowerCase();
   *
   *     if (path !== normalized) {
   *       return normalized;
   *     }
   *   });
   * });
   * ```
   *
   * @param ruleFn
   * Handler function that takes `$injector` and `$location` services as arguments.
   * You can use them to detect a url and return a different url as a string.
   *
   * @return [[UrlRouterProvider]] (`this`)
   */
  rule(ruleFn: RawNg1RuleFunction): UrlRouterProvider {
    if (!isFunction(ruleFn)) throw new Error("'rule' must be a function");

    const match = () => ruleFn(services.$injector, this.router.locationService);

    const rule = new BaseUrlRule(match, identity);
    this.router.urlService.rules.rule(rule);
    return this;
  }
開發者ID:angular-ui,項目名稱:ui-router,代碼行數:40,代碼來源:urlRouterProvider.ts

示例4: otherwise

  /**
   * Defines the path or behavior to use when no url can be matched.
   *
   * #### Example:
   * ```js
   * var app = angular.module('app', ['ui.router.router']);
   *
   * app.config(function ($urlRouterProvider) {
   *   // if the path doesn't match any of the urls you configured
   *   // otherwise will take care of routing the user to the
   *   // specified url
   *   $urlRouterProvider.otherwise('/index');
   *
   *   // Example of using function rule as param
   *   $urlRouterProvider.otherwise(function ($injector, $location) {
   *     return '/a/valid/url';
   *   });
   * });
   * ```
   *
   * @param rule
   * The url path you want to redirect to or a function rule that returns the url path or performs a `$state.go()`.
   * The function version is passed two params: `$injector` and `$location` services, and should return a url string.
   *
   * @return {object} `$urlRouterProvider` - `$urlRouterProvider` instance
   */
  otherwise(rule: string | RawNg1RuleFunction): UrlRouterProvider {
    const urlRules = this.router.urlService.rules;
    if (isString(rule)) {
      urlRules.otherwise(rule);
    } else if (isFunction(rule)) {
      urlRules.otherwise(() => rule(services.$injector, this.router.locationService));
    } else {
      throw new Error("'rule' must be a string or function");
    }

    return this;
  }
開發者ID:angular-ui,項目名稱:ui-router,代碼行數:38,代碼來源:urlRouterProvider.ts


注:本文中的@uirouter/core.isFunction函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。