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


TypeScript router.Location類代碼示例

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


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

示例1: describe

describe('Routing', () => {

    let location: Location;
    let router: Router;

    beforeEachProviders(() => [ 
        RouteRegistry,
        Location,
        provide(Router, {useClass: RootRouter}),
        provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppComponent})
    ]);

    beforeEach(inject([Router, Location], (r, l) => {
        router = r;
        location = l;
    }));

    it('Should navigate to Login', (done) => {   
        router.navigate(['Login']).then(() => {
            expect(location.path()).toBe('/login');
            done();
        }).catch(e => done.fail(e));
    });

    it('Should navigate to Register', (done) => {   
        router.navigate(['Register']).then(() => {
            expect(location.path()).toBe('/register');
            done();
        }).catch(e => done.fail(e));
    });

});
開發者ID:agvision,項目名稱:Angular_Seed_Karma,代碼行數:32,代碼來源:routing.ts

示例2: constructor

	constructor(txtFileDataService: TxtFileDataService, location: Location) {

		this.location = location;

		console.log(location.path())

		txtFileDataService.loadPageTitle().subscribe((data) => {
			this.pageTitle = data;
		});
	}
開發者ID:dodishes,項目名稱:glenwoodapt12,代碼行數:10,代碼來源:app.component.ts

示例3: describe

describe('Employee Component Tests', () => {
	let employeesComponent: EmployeesComponent;
	let location:Location;

	beforeEachProviders(() => [
		ROUTER_PROVIDERS,
		provide(Location, {useClass: SpyLocation}),
		provide(Router, {useClass: RootRouter}),
		provide(APP_BASE_HREF, {useValue: '/'}),
		provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppComponent}),
		provide(ApplicationRef, {useClass: MockApplicationRef}),
		provide(EmployeeService, {useClass: EmployeeService}),
		provide(EmployeesComponent, {useClass: EmployeesComponent})
	]);

	beforeEach(inject([EmployeesComponent, Location], (ec, l) => {
		employeesComponent = ec;
		location = l;
	}))
	
	it('should fetch the employee list on init', done => {
		let testEmployees = () => {
			expect(employeesComponent.employees.length).toBe(15);
			done();
		};

		employeesComponent.ngOnInit();

		setTimeout(testEmployees);
	});

	it('should navigate to the edit page', done => {
		let testNavigation = () => {
			expect(location.path()).toBe('/edit/55');
			done();
		};

		employeesComponent.goToEdit(55);

		setTimeout(testNavigation);
	});

	it('should navigate to the add a new employee page', done => {
		let testNavigation = () => {
			expect((location as any).path()).toBe('/add');
			done();
		};

		employeesComponent.goToAdd();

		setTimeout(testNavigation);
	});
});
開發者ID:mlzharov,項目名稱:employee-directory-angular-2-intro,代碼行數:53,代碼來源:employees.component.spec.ts

示例4: describe

describe('Employee Edit Component Tests', () => {
	let employeeEditComponent: EmployeeEditComponent;
	let location:Location;

	beforeEachProviders(() => [
		ROUTER_PROVIDERS,
		provide(Location, {useClass: SpyLocation}),
		provide(Router, {useClass: RootRouter}),
		provide(RouteParams, { useValue: new RouteParams({ id: '2' }) }),
		provide(APP_BASE_HREF, {useValue: '/'}),
		provide(ROUTER_PRIMARY_COMPONENT, {useValue: AppComponent}),
		provide(ApplicationRef, {useClass: MockApplicationRef}),
		provide(EmployeeService, {useClass: EmployeeService}),
		provide(EmployeeEditComponent, {useClass: EmployeeEditComponent})
	]);

	beforeEach(inject([EmployeeEditComponent, Location], (eec, l) => {
		employeeEditComponent = eec;
		location = l;
	}))
	
	it('should fetch an employee object on init', done => {
		let testEmployeePopulated = () => {
			expect(employeeEditComponent.employee).toBeDefined();
			expect(employeeEditComponent.employee.firstName).toBe('Dwight');
			expect(employeeEditComponent.employee.lastName).toBe('Schrute');
			done();
		};

		employeeEditComponent.ngOnInit();

		setTimeout(testEmployeePopulated);
	});

	it('should navigate to the employee list page', done => {
		let testNavigation = () => {
			expect(location.path()).toBe('/employees');
			done();
		};

		employeeEditComponent.backToDirectory({});

		setTimeout(testNavigation);
	});
});
開發者ID:mlzharov,項目名稱:employee-directory-angular-2-intro,代碼行數:45,代碼來源:employee-edit.component.spec.ts

示例5: if

 isSelected(path) {
   if(path === this.location.path()){
       return true;
   }
   else if(path.length > 0){
       return this.location.path().indexOf(path) > -1;
   }
 }
開發者ID:michidk,項目名稱:Angular2-Routing-Example,代碼行數:8,代碼來源:nav.component.ts

示例6: if

    getLinkStyle(path) {

        if(path === this.location.path()){
            return true;
        }
        else if(path.length > 0){
            return this.location.path().indexOf(path) > -1;
        }
    }
開發者ID:2947721120,項目名稱:angular-2-samples,代碼行數:9,代碼來源:app.ts

示例7: isActiveRoute

	public isActiveRoute(route: string): boolean {
		let path = this._location.path()
		if (path == '/'+route) {
			return true
		} else {
			return false
		}
	}
開發者ID:Dequisitor,項目名稱:MDash-Nodejs,代碼行數:8,代碼來源:home.router.component.ts

示例8: if

		client.session.subscribe((auth: FirebaseAuthData) => {
			router.recognize(location.path()).then((instruction: Instruction) => {
				if (auth && isAuthComponent(instruction)) {
					router.navigate(['/Dashboard']);
				} else if (!auth && !isAuthComponent(instruction)) {
					router.navigate(['/Auth', 'Login']);
				}
			});
		});
開發者ID:virajs,項目名稱:ng2-lab,代碼行數:9,代碼來源:app.ts

示例9: tryNavigateAfterReloading

    /**
     *
     * @returns {Promise.<string>} returns the original location where the browser comes from
     */
    public tryNavigateAfterReloading(): Promise<string> {
        const locationPath = this._location.path();

        return this.getChildRoute(locationPath)
            .then((carrier: RouteInstruction)=> {
                this._outstandingChildRoutingUrl = carrier.outstandingPath;
                return this._router.navigateByInstruction(carrier.instruction);
            })
            .then(() => locationPath);
    }
開發者ID:LVM-IT,項目名稱:spa-prototype,代碼行數:14,代碼來源:recursive.router.ts

示例10:

      .subscribe((isAuthorized: boolean) => {
        if (isFirst)
          return isFirst = false

        const isLogin = /login/.test(this._location.path())

        if (isAuthorized && !isLogin)
          return

        if (isLogin && isAuthorized)
          this._router.navigate(['Home'])
        else
          this._router.navigate(['Login'])
      })
開發者ID:MikaAK,項目名稱:trello-burndown,代碼行數:14,代碼來源:index.ts


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