반응형
<a> 태그로 target="_blank" 로 하여 새로운 창을 여니 새탭으로 열린다.
팝업으로 띄우려면 window.open(url, title, option)을 하면 되는데
Angular에서는 어떻게 하나 찾아보니 아래와 같았다.
app.component.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import { Component, OnInit } from '@angular/core'; import {WindowRef} from './windowRef'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent implements OnInit { title = 'app'; constructor( private winRef: WindowRef ) { console.log(winRef.nativeWindow); } openWindow() { const popOption = 'width=300'; this.winRef.nativeWindow.open('http://google.co.kr', "", popOption); } ngOnInit(): void { }; } | cs |
app.component.html
1 | <a (click)="openWindow()">Click</a> | cs |
windowRef.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import {Injectable} from '@angular/core'; function _window(): any { // return the native window obj return window; } @Injectable() export class WindowRef { get nativeWindow(): any { return _window(); } } | cs |
새창으로 팝업이 열린다~
반응형
'엉터리 개발 이야기 > angular2+' 카테고리의 다른 글
[Angular2+] e2e test debugging (0) | 2018.02.01 |
---|---|
[Angular2+] e2e test(End To End Test) 셋팅 (0) | 2018.02.01 |
[Angular2+] lite-server 로 간단한 웹 서버 구동하기 (0) | 2017.11.12 |
[Angular2+] ng serve 호스트, 포트 지정하여 실행하기 (1) | 2017.11.11 |
[angular] angular-in-memory-web-api 모듈 설치 (0) | 2017.10.19 |