当前位置: 首页>>代码示例>>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;未经允许,请勿转载。