This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { PLATFORM_ID } from '@angular/core'; | |
| import { isPlatformBrowser } from '@angular/common'; | |
| @Component({...}) | |
| export class DemoComponent implements OnInit { | |
| constructor(@Inject(PLATFORM_ID) private platformId: Object) { } | |
| ngOnInit() { | |
| if (isPlatformBrowser(this.platformId)){ | |
| // here you can access window | |
| console.log(window); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension RawRepresentable where Self: Hashable { | |
| private static func iterateEnum<T: Hashable>(_: T.Type) -> AnyIterator<T> { | |
| var index = 0 | |
| let closure: () -> T? = { | |
| let next = withUnsafePointer(to: &index) { | |
| $0.withMemoryRebound(to: T.self, capacity: 1) { $0.pointee } | |
| } | |
| guard next.hashValue == index else { return nil } |