constructor (
private myService: MyService,
) {}
onMyButton() {
this.myService.triggerOnMyButton();
}
constructor (
private myService: MyService,
) {}
ngOnInit() {
this.myService.trigger$.subscribe(() => this.myMethod());
}
private _trigger = new Subject<void>();
get trigger$() {
return this._trigger.asObservable();
}
public triggerOnMyButton() {
this._trigger.next();
}
export default class MyClass {
start() {
this.elem = document.querySelector('.elem');
this.elem.addEventListener('click', (event) => this.check(event));
}
check(e) {
//код
}
}
this.elem.addEventListener('click', this.check.bind(this));
$ = jQuery; // загрузили данные
delete window.$ // - и нету.
// После уничтожения всех ссылок, GC вычистит саму сущность из памяти.
@Injectable({
providedIn: 'root',
})
export class MyService {
public myVar$ = new Subject();
}
<div>{{ myService.myVar$ | async}}</div>
export class Comp1Component {
constructor(
public myService: MyService
) {}
}
export class Comp2Component {
constructor(
public myService: MyService
) {}
myFunc(){
this.myService.myVar$.next(1000);
}
}
cat1.__proto__.__proto__.__proto__ === Dog.prototype
Dog.prototype = Mammal.prototype;