mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
Tightened up the ILocationService typings a little
This commit is contained in:
@@ -599,4 +599,53 @@ angular.module('copyExample', [])
|
||||
};
|
||||
|
||||
$scope.reset();
|
||||
}]);
|
||||
}]);
|
||||
|
||||
module locationTests {
|
||||
|
||||
var $location: ng.ILocationService;
|
||||
|
||||
/*
|
||||
* From https://docs.angularjs.org/api/ng/service/$location
|
||||
*/
|
||||
|
||||
// given url http://example.com/#/some/path?foo=bar&baz=xoxo
|
||||
var searchObject = $location.search();
|
||||
// => {foo: 'bar', baz: 'xoxo'}
|
||||
|
||||
|
||||
// set foo to 'yipee'
|
||||
$location.search('foo', 'yipee');
|
||||
// => $location
|
||||
|
||||
/*
|
||||
* From: https://docs.angularjs.org/guide/$location
|
||||
*/
|
||||
|
||||
// in browser with HTML5 history support:
|
||||
// open http://example.com/#!/a -> rewrite to http://example.com/a
|
||||
// (replacing the http://example.com/#!/a history record)
|
||||
$location.path() == '/a'
|
||||
|
||||
$location.path('/foo');
|
||||
$location.absUrl() == 'http://example.com/foo'
|
||||
|
||||
$location.search() == {}
|
||||
$location.search({ a: 'b', c: true });
|
||||
$location.absUrl() == 'http://example.com/foo?a=b&c'
|
||||
|
||||
$location.path('/new').search('x=y');
|
||||
$location.url() == 'new?x=y'
|
||||
$location.absUrl() == 'http://example.com/new?x=y'
|
||||
|
||||
// in browser without html5 history support:
|
||||
// open http://example.com/new?x=y -> redirect to http://example.com/#!/new?x=y
|
||||
// (again replacing the http://example.com/new?x=y history item)
|
||||
$location.path() == '/new'
|
||||
$location.search() == { x: 'y' }
|
||||
|
||||
$location.path('/foo/bar');
|
||||
$location.path() == '/foo/bar'
|
||||
$location.url() == '/foo/bar?x=y'
|
||||
$location.absUrl() == 'http://example.com/#!/foo/bar?x=y'
|
||||
}
|
||||
64
angularjs/angular.d.ts
vendored
64
angularjs/angular.d.ts
vendored
@@ -557,25 +557,71 @@ declare module ng {
|
||||
assign(context: any, value: any): any;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// LocationService
|
||||
// see http://docs.angularjs.org/api/ng.$location
|
||||
// see http://docs.angularjs.org/api/ng.$locationProvider
|
||||
// see http://docs.angularjs.org/guide/dev_guide.services.$location
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* $location - $locationProvider - service in module ng
|
||||
* see https://docs.angularjs.org/api/ng/service/$location
|
||||
*/
|
||||
interface ILocationService {
|
||||
absUrl(): string;
|
||||
hash(): string;
|
||||
hash(newHash: string): ILocationService;
|
||||
host(): string;
|
||||
|
||||
/**
|
||||
* Return path of current url
|
||||
*/
|
||||
path(): string;
|
||||
path(newPath: string): ILocationService;
|
||||
|
||||
/**
|
||||
* Change path when called with parameter and return $location.
|
||||
* Note: Path should always begin with forward slash (/), this method will add the forward slash if it is missing.
|
||||
*
|
||||
* @param path New path
|
||||
*/
|
||||
path(path: string): ILocationService;
|
||||
|
||||
port(): number;
|
||||
protocol(): string;
|
||||
replace(): ILocationService;
|
||||
|
||||
/**
|
||||
* Return search part (as object) of current url
|
||||
*/
|
||||
search(): any;
|
||||
search(parametersMap: any): ILocationService;
|
||||
search(parameter: string, parameterValue: any): ILocationService;
|
||||
|
||||
/**
|
||||
* Change search part when called with parameter and return $location.
|
||||
*
|
||||
* @param search When called with a single argument the method acts as a setter, setting the search component of $location to the specified value.
|
||||
*
|
||||
* If the argument is a hash object containing an array of values, these values will be encoded as duplicate search parameters in the url.
|
||||
*/
|
||||
search(search: any): ILocationService;
|
||||
|
||||
/**
|
||||
* Change search part when called with parameter and return $location.
|
||||
*
|
||||
* @param search New search params
|
||||
* @param paramValue If search is a string, then paramValue will override only a single search property. If paramValue is null, the property specified via the first argument will be deleted.
|
||||
*/
|
||||
search(search: string, paramValue: string): ILocationService;
|
||||
|
||||
/**
|
||||
* Change search part when called with parameter and return $location.
|
||||
*
|
||||
* @param search New search params
|
||||
* @param paramValue If paramValue is an array, it will override the property of the search component of $location specified via the first argument.
|
||||
*/
|
||||
search(search: string, paramValue: string[]): ILocationService;
|
||||
|
||||
/**
|
||||
* Change search part when called with parameter and return $location.
|
||||
*
|
||||
* @param search New search params
|
||||
* @param paramValue If paramValue is true, the property specified via the first argument will be added with no value nor trailing equal sign.
|
||||
*/
|
||||
search(search: string, paramValue: boolean): ILocationService;
|
||||
|
||||
url(): string;
|
||||
url(url: string): ILocationService;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user