<div *ngIf="authTokenService.currentUserData">
почемуто не выводится установленная по умолчанию аватарка
import { SafeUrl, DomSanitizer } from '@angular/platform-browser'
@Any()
export class Any {
public defaultAvatarUrl: SafeUrl
constructor(private readonly sanitizer: DomSanitizer) {
this.defaultAvatar = this.sanitizer.bypassSecurityTrustUrl(
'assets/img/empty_photo.png'
)
}
}
public get userAvatar(): SafeUrl {
return this.sanitizer.bypassSecurityTrustUrl(
this.authTokenService.currentUserData
? this.authTokenService.currentUserData.user_photo
: 'assets/img/empty_photo.png'
)
}
import {
Component,
ViewChild,
ViewContainerRef,
OnInit,
ComponentFactoryResolver,
Injector,
EmbeddedViewRef,
ElementRef
} from '@angular/core'
import { Type } from '@angular/core'
@Component({
selector: 'app-root',
template: '<h1>Скомпилируй</h1> <div #outlet></div>',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
public title = 'app'
public AnyComponent
@ViewChild('outlet') outlet: ElementRef
constructor(
private readonly factoryResolver: ComponentFactoryResolver,
private readonly injector: Injector
) {}
public ngOnInit() {
this.appendComponent(this.AnyComponent)
}
public appendComponent<T>(component: Type<T>) {
const componentRef = this.factoryResolver
.resolveComponentFactory(component)
.create(this.injector)
const domElem = (componentRef.hostView as EmbeddedViewRef<any>)
.rootNodes[0] as HTMLElement
this.outlet.nativeElement.appendChild(domElem)
}
}
import { Injectable, Injector } from '@angular/core'
import {
HttpEvent,
HttpInterceptor,
HttpHandler,
HttpRequest
} from '@angular/common/http'
import { Observable } from 'rxjs/Observable'
import 'rxjs/add/observable/throw'
import 'rxjs/add/operator/catch'
@Injectable()
export class MyHttpInterceptor implements HttpInterceptor {
intercept(
req: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
console.log('intercepted request ... ')
return next.handle(req).catch((error, caught) => {
// Проверяем код ошибки. Берём роутер и перенаправляем куда вам угодно.
return Observable.throw(error)
}) as any
}
}
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent extends HelloComponent { // Вот тут
name = 'Angular 6';
constructor() {
super(); // Первый console.log('...')
console.log('constructor app');
}
}
<hello name="{{ name }}"></hello> // Второй console.log('...')
<p>
Start editing to see some magic happen :)
</p>
child.addEventListener('click', function(){
alert("Привет, я - Child");
})
child.addEventListener('mousedown', function(){
alert("Привет, я - Parent");
})
Не нашел актуальных
<section>
<input [(ngModel)]=currentString>
{{currentString.length}}
</section>
<your-tooltip [hidden]="currentString.length > 10">
Lorem, ipsum.
</your-tooltip>
var elementClick = $(this).attr("href");
var destination = $(elementClick).offset().top;
<div class="audio">
<span>Название аудио</span>
<audio controls src="http://www.sample-videos.com/audio/mp3/crowd-cheering.mp3" >
<p>Ваш браузер не поддерживает аудио</p>
</audio>
</div>
<div class="audio">
<span>Название аудио</span>
<audio controls src="http://www.sample-videos.com/audio/mp3/crowd-cheering.mp3" >
<p>Ваш браузер не поддерживает аудио</p>
</audio>
</div>
<div class="audio">
<span>Название аудио</span>
<audio controls src="http://www.sample-videos.com/audio/mp3/crowd-cheering.mp3" >
<p>Ваш браузер не поддерживает аудио</p>
</audio>
</div>
<div class="audio">
<span>Название аудио</span>
<audio controls src="http://www.sample-videos.com/audio/mp3/crowd-cheering.mp3" >
<p>Ваш браузер не поддерживает аудио</p>
</audio>
</div>
const audioList = document.querySelectorAll('audio')
let currentAudio
Array.prototype.forEach.call(audioList, audio => {
audio.addEventListener('play', e => {
if (currentAudio) currentAudio.pause()
currentAudio = e.target
})
})
const arr = this._slides.map((_, i) => i) //Если _slides массив.
console.log(arr)
// -------------
const arr = Array.prototype.map.call(this._slides, (_, i) => i)
console.log(arr)