.then(HtmlResult => HtmlResult.text())
.then(tmpHtml => {
console.log('html result ->> ', tmpHtml);
return tmpHtml;
})
let html = await apiManager.makeRequest(data['key'], data['id'], comment) console.log(' -- from async html await func console->>> ', html ); // тут переменная html == undefined
makeRequest: (key, id, comment ) =>{
return fetch(`url2`,{
method: "POST",
.....
await Promise.all(doc.map(item => (async(item) { /* ... */ })(item)))
Promise.all
- принимает массив промисов(async(item) { /* ... */ })(item)
- async IIFE, возвращающее промисdoc.map(item => ...)
- делает массив event.preventDefault()
для того, чтобы браузер не переходил по ссылке. async function delayedPromise(cb) {
const delay = () => new Promise(resolve => setTimeout(resolve, 3000));
const result = await Promise.all([cb(), delay()]);
return result[0];
}
async function runPromisesInSequence(promises) {
for (let promise of promises) {
console.log(await delayedPromise(promise), new Date());
}
}
const pr1 = () => new Promise(res => setTimeout(() => res('r1'), 1000));
const pr2 = () => new Promise(res => setTimeout(() => res('r2'), 5000));
const pr3 = () => new Promise(res => setTimeout(() => res('r3'), 0));
const y = [pr1, pr2, pr3];
runPromisesInSequence(y);
const pr1 = new Promise(res => setTimeout(() => res('r1'), 1000));
private ck = new BehaviorSubject(false);
public setCk(val: boolean): void {
this.ck.nex(val);
}
public getCk(): Observable<boolean> {
return this.ck.asObservable();
}
// можно оформить как аксессоры, но так наглядней
private subs = new Subscription();
public ck: boolean;
constructor(private service: MyService) {}
ngOnInit() {
const s0 = this.service.getCk().subscribe(ck => this.ck = ck); // тут можно добавить какие-то действия при изменении данных
this.subs.add(s0);
}
ngOnDestroy() {
this.subs.unsubscribe();
}
const src = 'Привет мир!';
const suffix = '98';
const srcArr = src.split(' ');
const reversed = srcArr.map(el => el.split('').reverse().join(''));
const target = reversed.map(el => el+suffix).join(' ');
console.log(target);
const src = 'Привет мир!';
const suffix = '98';
const target = src.split(' ').map(el => el.split('').reverse().join('')+suffix).join(' ');
console.log(target);
this.prop
this['prop']
const a = 'prop';
this[a]
document.documentElement.style.backgroundColor = "#ff00ff";
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: host in /srv/SaraFannTest/public/index.php on line <i>33</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0001</td><td bgcolor='#eeeeec' align='right'>356992</td><td bgcolor='#eeeeec'>{main}( )</td><td title='/srv/SaraFannTest/public/index.php' bgcolor='#eeeeec'>.../index.php<b>:</b>0</td></tr>
</table></font>
<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: scheme in /srv/SaraFannTest/public/index.php on line <i>34</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0001</td><td bgcolor='#eeeeec' align='right'>356992</td><td bgcolor='#eeeeec'>{main}( )</td><td title='/srv/SaraFannTest/public/index.php' bgcolor='#eeeeec'>.../index.php<b>:</b>0</td></tr>
</table></font>