• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript router.Location类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript router.LocationStrategy类代码示例发布时间:2022-05-25
下一篇:
TypeScript router.CanActivate函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap