ngOnInit() { if (this.link) { // input this.urlSafe = this.sanitizer.bypassSecurityTrustResourceUrl(this.link); } else { this.subscription = this.activeroute.params.subscribe(params => { // routing this.link = params['url']; this.urlSafe = this.sanitizer.bypassSecurityTrustResourceUrl(this.link); }); } }
function () { function AppModule() { } AppModule = __decorate([ core_1.NgModule({ imports: [platform_browser_1.BrowserModule, http_1.HttpModule], declarations: [app_component_1.AppComponent], bootstrap: [app_component_1.AppComponent] }), __metadata('design:paramtypes', []) ], AppModule); return AppModule; }()
setTitle( string ){ this.titleService.setTitle(string); }
updateTitle(event) { let newTitle = this.getNewTitle(event.url); this.titleService.setTitle(newTitle); }
describe('AppComponent with TCB', function () { beforeEach(() => { TestBed.configureTestingModule({declarations: [AppComponent]}); }); it('should instantiate component', () => { let fixture = TestBed.createComponent(AppComponent); expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent'); }); it('should have expected <h1> text', () => { let fixture = TestBed.createComponent(AppComponent); fixture.detectChanges(); let h1 = fixture.debugElement.query(el => el.name === 'h1').nativeElement; // it works h1 = fixture.debugElement.query(By.css('h1')).nativeElement; // preferred expect(h1.innerText).toMatch(/angular app/i, '<h1> should say something about "Angular App"'); }); });
constructor(private projectService: ProjectService, private winRef: WindowRef, public dialog: MatDialog, private changeDetector: ChangeDetectorRef, private translateService: TranslateService, private gaugesManager: GaugesManager, private viewContainerRef: ViewContainerRef, private resolver: ComponentFactoryResolver, private mdIconRegistry: MatIconRegistry, private sanitizer: DomSanitizer) { mdIconRegistry.addSvgIcon('group', sanitizer.bypassSecurityTrustResourceUrl('/assets/images/group.svg')); mdIconRegistry.addSvgIcon('to_bottom', sanitizer.bypassSecurityTrustResourceUrl('/assets/images/to-bottom.svg')); mdIconRegistry.addSvgIcon('to_top', sanitizer.bypassSecurityTrustResourceUrl('/assets/images/to-top.svg')); // this.gaugesManager.stopDemo(); }
describe('AppComponent with TCB', function () { it('should instantiate component', async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { tcb.createAsync(AppComponent).then(fixture => { expect(fixture.componentInstance instanceof AppComponent).toBe(true, 'should create AppComponent'); }); }))); it('should have expected <h1> text', async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => { tcb.createAsync(AppComponent).then(fixture => { // fixture.detectChanges(); // would need to resolve a binding but we don't have a binding let h1 = fixture.debugElement.query(el => el.name === 'h1').nativeElement; // it works h1 = fixture.debugElement.query(By.css('h1')).nativeElement; // preferred expect(h1.innerText).toMatch(/angular 2 app/i, '<h1> should say something about "Angular 2 App"'); }); }))); });
ngOnInit(): void { /** * We'll use reactive programming to set our title documents */ this.router.events .filter(event => event instanceof NavigationEnd) .map(() => this.activatedRoute) .map(route => { while (route.firstChild) { route = route.firstChild; } return route; }) .filter(route => route.outlet === 'primary') .mergeMap(route => route.data) .subscribe(event => { this.titleService.setTitle(event['title'] + config.suffixTitle); }); }
transform(url: any){ url = url.replace("watch?v=", "embed/"); return this.sanitizer.bypassSecurityTrustResourceUrl(url); }
describe('AppComponent', function () { let de: DebugElement; let comp: AppComponent; let fixture: ComponentFixture<AppComponent>; beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [ AppComponent ] }) .compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(AppComponent); comp = fixture.componentInstance; de = fixture.debugElement.query(By.css('h1')); }); it('should create component', () => expect(comp).toBeDefined() ); it('should have expected <h1> text', () => { fixture.detectChanges(); const h1 = de.nativeElement; expect(h1.innerText).toMatch(/angular/i, '<h1> should say something about "Angular"'); }); });
describe('AppComponent', function () { var de; var comp; var fixture; beforeEach(testing_1.async(function () { testing_1.TestBed.configureTestingModule({ declarations: [app_component_1.AppComponent] }) .compileComponents(); })); beforeEach(function () { fixture = testing_1.TestBed.createComponent(app_component_1.AppComponent); comp = fixture.componentInstance; de = fixture.debugElement.query(platform_browser_1.By.css('h1')); }); it('should create component', function () { return expect(comp).toBeDefined(); }); it('should have expected <h1> text', function () { fixture.detectChanges(); var h1 = de.nativeElement; expect(h1.innerText).toMatch(/angular/i, '<h1> should say something about "Angular"'); }); });
ngOnInit() { this.router.events .filter((event) => event instanceof NavigationEnd) .map(() => this.route) .map((route) => { while (route.firstChild) route = route.firstChild; return route; }) .filter((route) => route.outlet === 'primary') .mergeMap((route) => route.data) .subscribe((data) => { this.titleService.setTitle(data.title); if (data.title !== 'Login' && data !== undefined) { if (data.permMap.indexOf(this.auth.roles[0]) < 0) { localStorage.clear(); this.router.navigate(['/403']); } } }); }
loadLink(link: string) { this.link = link; if (this.link) { this.urlSafe = this.sanitizer.bypassSecurityTrustResourceUrl(this.link); } }
constructor ( protected _ngZone : NgZone , private _layoutService : LayoutService , private _socketService : SocketService , private _dataframeAccount : DataframeAccount , private _mouseService : MouseService , private _designerService : DesignerService , private _dataframeDesignerTree : DataframeDesignerTree , private _mdIconRegistry : MdIconRegistry , private _sanitizer : DomSanitizer ) { _mdIconRegistry .addSvgIcon( 'merge', _sanitizer.bypassSecurityTrustResourceUrl ( './assets/merge.svg' ) ); _mdIconRegistry .addSvgIcon('split', _sanitizer.bypassSecurityTrustResourceUrl ( './assets/split.svg' ) ); }
constructor ( protected _ngZone : NgZone , private _layoutService : LayoutService , private _socketService : SocketService , private _dataframeAccount : DataframeAccount , private _mouseService : MouseService , private _designerService : DesignerService , private _dataframeDesignerTree : DataframeDesignerTree , private _mdIconRegistry : MdIconRegistry , private _sanitizer : DomSanitizer ) { _mdIconRegistry .addSvgIcon( 'merge', _sanitizer.bypassSecurityTrustResourceUrl ( './assets/merge.svg' ) ); _mdIconRegistry .addSvgIcon('split', _sanitizer.bypassSecurityTrustResourceUrl ( './assets/split.svg' ) ); }