本文整理匯總了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));
});
});
示例2: constructor
constructor(txtFileDataService: TxtFileDataService, location: Location) {
this.location = location;
console.log(location.path())
txtFileDataService.loadPageTitle().subscribe((data) => {
this.pageTitle = data;
});
}
示例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);
});
});
示例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);
});
});
示例5: if
isSelected(path) {
if(path === this.location.path()){
return true;
}
else if(path.length > 0){
return this.location.path().indexOf(path) > -1;
}
}
示例6: if
getLinkStyle(path) {
if(path === this.location.path()){
return true;
}
else if(path.length > 0){
return this.location.path().indexOf(path) > -1;
}
}
示例7: isActiveRoute
public isActiveRoute(route: string): boolean {
let path = this._location.path()
if (path == '/'+route) {
return true
} else {
return false
}
}
示例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']);
}
});
});
示例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);
}
示例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'])
})