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


TypeScript common.LocationStrategy類代碼示例

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


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

示例1: constructor

  constructor(public platformStrategy: LocationStrategy) {
    super(1);

    platformStrategy.onPopState(event => this._update('pop'));

    const browserBaseHref = this.platformStrategy.getBaseHref();
    this._baseHref = stripTrailingSlash(stripIndexHtml(browserBaseHref));
    this._update('push');
  }
開發者ID:SekibOmazic,項目名稱:router,代碼行數:9,代碼來源:router.ts

示例2: it

  it('should navigate back', fakeAsync(() => {
    const {fixture, rootRenderer} = initTest(TestComponent, `<View><router-outlet></router-outlet></View>`);
    const location: LocationStrategy = getTestBed().get(LocationStrategy);
    const router: Router = getTestBed().get(Router);
    router.initialNavigation();
    tick();
    fixture.detectChanges();
    rootRenderer.executeCommands();
    expect(mock.commandLogs.toString()).toEqual(
      'CREATE+2+test-cmp+{},CREATE+3+native-view+{},CREATE+4+router-outlet+{},ATTACH+1+2+0,ATTACH+2+3+0,ATTACH+3+4+0,' +
      'CREATE+5+cmp-a+{},CREATE+6+native-text+{},CREATE+7+native-rawtext+{"text":"a"},ATTACH+6+7+0,ATTACH+5+6+0,ATTACH+3+5+1');
    mock.clearLogs();

    router.navigateByUrl('/b')
      .then((_: any) => {
        tick();
        fixture.detectChanges();
        rootRenderer.executeCommands();
        expect(mock.commandLogs.toString()).toEqual(
          'CREATE+8+cmp-b+{},CREATE+9+native-text+{},CREATE+10+native-rawtext+{"text":"b"},DETACH+3+1,ATTACH+3+8+1,ATTACH+9+10+0,ATTACH+8+9+0');
        mock.clearLogs();
      })
      .then((_: any) => {
        location.back();
        tick();
        fixture.detectChanges();
        rootRenderer.executeCommands();
        expect(mock.commandLogs.toString()).toEqual(
          'CREATE+11+cmp-a+{},CREATE+12+native-text+{},CREATE+13+native-rawtext+{"text":"a"},DETACH+3+1,ATTACH+3+11+1,ATTACH+12+13+0,ATTACH+11+12+0');
      });
  }));
開發者ID:angular,項目名稱:react-native-renderer,代碼行數:31,代碼來源:router_spec.ts

示例3: constructor

  constructor(public platformStrategy: LocationStrategy) {
    super({ path: _path(platformStrategy), type: 'push' });

    platformStrategy.onPopState(event => this._update('pop'));

    this._baseHref = _getBaseHref(platformStrategy);
  }
開發者ID:gravity-addiction,項目名稱:router,代碼行數:7,代碼來源:router.ts

示例4: constructor

	// I initialize the retro-location service. This provides an API that is 
	// reminiscent of the AngularJS 1.x $location service.
	constructor( locationStrategy: LocationStrategy ) {

		this.locationStrategy = locationStrategy;
		this.popStateEvents = new Subject();

		// When the underlying location implementation emits a PopStateEvent, we 
		// want to communicate that out to any clients that may be subscribed to the
		// RetroLocation events.
		this.locationStrategy.onPopState(
			( event: PopStateEvent | HashChangeEvent ) : void => {

				// Since RetroLocation will emit this event when the location is 
				// changed programmatically, we want to limit it to a single event-type,
				// popstate, in order to make things a bit more predictable.
				if ( event.type === "popstate" ) {

					this.popStateEvents.next({
						url: this.url(),
						pop: true,
						type: "popstate"
					});

				}

			}
		);

	}	
開發者ID:bennadel,項目名稱:JavaScript-Demos,代碼行數:30,代碼來源:retro-location.ts

示例5: it

  it('should navigate back', async(inject([TestComponentBuilder, ReactNativeRootRenderer], (tcb: TestComponentBuilder, _rootRenderer: ReactNativeRootRenderer) => {
    var rootRenderer = _rootRenderer;
    var router: Router;
    var location: LocationStrategy;
    tcb.createAsync(TestComponent).then((fixture: ComponentFixture<TestComponent>) => {
      router = fixture.componentInstance.router;
      location = fixture.componentInstance.location;
      fixture.detectChanges();
      rootRenderer.executeCommands();
      mock.clearLogs();

      return new Promise((resolve: any) => {
        setTimeout(() => {
          rootRenderer.executeCommands();
          expect(mock.commandLogs.toString()).toEqual(
            'CREATE+5+cmp-a+{},CREATE+6+native-text+{},CREATE+7+native-rawtext+{"text":"a"},ATTACH+6+7+0,ATTACH+5+6+0,ATTACH+3+5+1');
          mock.clearLogs();

          router.navigateByUrl('/b')
          .then((_: any) => {
            rootRenderer.executeCommands();
            expect(mock.commandLogs.toString()).toEqual(
              'CREATE+8+cmp-b+{},CREATE+9+native-text+{},CREATE+10+native-rawtext+{"text":"b"},DETACH+3+1,ATTACH+3+8+1,ATTACH+9+10+0,ATTACH+8+9+0');
            mock.clearLogs();
          })
          .then((_: any) => {
            location.back();
            setTimeout(() => {
              rootRenderer.executeCommands();
              expect(mock.commandLogs.toString()).toEqual(
                'CREATE+11+cmp-a+{},CREATE+12+native-text+{},CREATE+13+native-rawtext+{"text":"a"},DETACH+3+1,ATTACH+3+11+1,ATTACH+12+13+0,ATTACH+11+12+0');
              resolve();
            }, 30);
          });

        }, 0);
      });
    });
  })));
開發者ID:DavyDuDu,項目名稱:react-native-renderer,代碼行數:39,代碼來源:router_spec.ts

示例6: tick

 .then((_: any) => {
   location.back();
   tick();
   fixture.detectChanges();
   rootRenderer.executeCommands();
   expect(mock.commandLogs.toString()).toEqual(
     'CREATE+11+cmp-a+{},CREATE+12+native-text+{},CREATE+13+native-rawtext+{"text":"a"},DETACH+3+1,ATTACH+3+11+1,ATTACH+12+13+0,ATTACH+11+12+0');
 });
開發者ID:angular,項目名稱:react-native-renderer,代碼行數:8,代碼來源:router_spec.ts

示例7: setTimeout

 .then((_: any) => {
   location.back();
   setTimeout(() => {
     rootRenderer.executeCommands();
     expect(mock.commandLogs.toString()).toEqual(
       'CREATE+11+cmp-a+{},CREATE+12+native-text+{},CREATE+13+native-rawtext+{"text":"a"},DETACH+3+1,ATTACH+3+11+1,ATTACH+12+13+0,ATTACH+11+12+0');
     resolve();
   }, 30);
 });
開發者ID:DavyDuDu,項目名稱:react-native-renderer,代碼行數:9,代碼來源:router_spec.ts

示例8: url

	public url( newUrl?: string ) : RetroLocation | string {

		// Return the existing url.
		if ( newUrl === undefined ) {

			return( this.locationStrategy.path( true ) ); // true = Include Hash.

		}

		// Set the new url.
		this.navigate( this.parseUrl( newUrl ) );

		return( this );

	}
開發者ID:bennadel,項目名稱:JavaScript-Demos,代碼行數:15,代碼來源:retro-location.ts

示例9: navigate

	// I navigate to the location defined by the given URL segments (pathname, search, 
	// and hash).
	private navigate( urlSegments: UrlSegments ) : void {

		var url = urlSegments.pathname;

		if ( urlSegments.search ) {

			url += ( "?" + urlSegments.search );

		}

		if ( urlSegments.hash ) {

			url += ( "#" + urlSegments.hash );

		}

		// Only push the state if the URL has actually changed. We only need this 
		// because the RetroLocation emits an event and we want this event to be a bit 
		// more closely tied to an actual change in the location.
		if ( url !== this.url() ) {

			this.locationStrategy.pushState(
				// pushState - all the other strategies appear to pass NULL here.
				null,
				// title - all the other strategies appear to pass empty-string here.
				"",
				// path - we are encoding the entire location into the path.
				url,
				// queryParams - we are baking these into the path (above).
				""
			);

			this.popStateEvents.next({
				url: url,
				pop: true,
				type: "popstate"
			});
			
		}

	}
開發者ID:bennadel,項目名稱:JavaScript-Demos,代碼行數:43,代碼來源:retro-location.ts

示例10:

 _goBack() {
   this._locationStrategy.back();
 }
開發者ID:angular,項目名稱:react-native-renderer,代碼行數:3,代碼來源:router.ts


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